0

I have an app that uses gmap to get markers from webservice and present them on the map. This is the layout code that works great

<fragment
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/map"
    android:name="com.google.android.gms.maps.SupportMapFragment"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.example.hp.fakeyourlocation.map.LocationChooser">


    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical" >
    <TableRow
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:weightSum="10">
        <Switch
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/hotel"
            android:text="Hoteli"
            android:padding="10dp"
            android:layout_marginTop="20dp"
            android:paddingRight="10dp"/>
        <Switch
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/hostel"
            android:text="Hosteli"
            android:padding="10dp"
            android:layout_marginTop="20dp"
            android:paddingRight="10dp"/>
        <Switch
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/apartmani"
            android:text="Apartmani"
            android:padding="10dp"
            android:layout_marginTop="20dp"
            android:paddingRight="10dp"/>
    </TableRow>
        <TableRow
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:gravity="center"
            android:weightSum="10">
            <Switch
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:id="@+id/hotel1"
                android:text="Hoteli"
                android:padding="10dp"
                android:layout_marginTop="20dp"
                android:paddingRight="10dp"/>
            <Switch
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:id="@+id/hostel2"
                android:text="Hosteli"
                android:padding="10dp"
                android:layout_marginTop="20dp"
                android:paddingRight="10dp"/>
            <Switch
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:id="@+id/apartmani2"
                android:text="Apartmani"
                android:padding="10dp"
                android:layout_marginTop="20dp"
                android:paddingRight="10dp"/>
        </TableRow>
    </LinearLayout>
    <Button
        android:layout_width="100dp"
        android:layout_height="70dp"
        android:layout_gravity="center|bottom"
        android:id="@+id/button2"
        android:text="Show my current location"
        android:padding="10dp"/>
    <Switch
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/pocisti"
        android:layout_gravity="left|bottom"
        android:text="Ukloni oznake"
        android:padding="10dp"
        android:layout_marginTop="20dp"
        android:paddingRight="10dp"/>

    </fragment>

Instead of switches in the main screen I wanted to add to slide menu. Once I add the code for slide menu to the end of this file, I can see the slide menu but the google map stops working. This is the new code that is not working

<fragment
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/map"
    android:name="com.google.android.gms.maps.SupportMapFragment"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.example.hp.fakeyourlocation.map.LocationChooser">


    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical" >
    <TableRow
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:weightSum="10">
        <Switch
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/hotel"
            android:text="Hoteli"
            android:padding="10dp"
            android:layout_marginTop="20dp"
            android:paddingRight="10dp"/>
        <Switch
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/hostel"
            android:text="Hosteli"
            android:padding="10dp"
            android:layout_marginTop="20dp"
            android:paddingRight="10dp"/>
        <Switch
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/apartmani"
            android:text="Apartmani"
            android:padding="10dp"
            android:layout_marginTop="20dp"
            android:paddingRight="10dp"/>
    </TableRow>
        <TableRow
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:gravity="center"
            android:weightSum="10">
            <Switch
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:id="@+id/hotel1"
                android:text="Hoteli"
                android:padding="10dp"
                android:layout_marginTop="20dp"
                android:paddingRight="10dp"/>
            <Switch
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:id="@+id/hostel2"
                android:text="Hosteli"
                android:padding="10dp"
                android:layout_marginTop="20dp"
                android:paddingRight="10dp"/>
            <Switch
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:id="@+id/apartmani2"
                android:text="Apartmani"
                android:padding="10dp"
                android:layout_marginTop="20dp"
                android:paddingRight="10dp"/>
        </TableRow>
    </LinearLayout>
    <Button
        android:layout_width="100dp"
        android:layout_height="70dp"
        android:layout_gravity="center|bottom"
        android:id="@+id/button2"
        android:text="Show my current location"
        android:padding="10dp"/>
    <Switch
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/pocisti"
        android:layout_gravity="left|bottom"
        android:text="Ukloni oznake"
        android:padding="10dp"
        android:layout_marginTop="20dp"
        android:paddingRight="10dp"/>
    <android.support.v4.widget.DrawerLayout android:layout_height="match_parent" android:layout_width="match_parent" android:id="@+id/drawer_layout" xmlns:android="http://schemas.android.com/apk/res/android">

    <!-- As the main content view, the view below consumes the entire space available using match_parent in both dimensions. -->


    <FrameLayout android:layout_height="match_parent" android:layout_width="match_parent" android:id="@+id/content_frame"/>

    <!-- android:layout_gravity="start" tells DrawerLayout to treat this as a sliding drawer on the left side for left-to-right languages and on the right side for right-to-left languages. The drawer is given a fixed width in dp and extends the full height of the container. A solid background is used for contrast with the content view. -->


    <ListView android:layout_height="match_parent" android:layout_width="240dp" android:id="@+id/left_drawer" android:background="#111" android:dividerHeight="0dp" android:divider="@android:color/transparent" android:choiceMode="singleChoice" android:layout_gravity="start"/>

</android.support.v4.widget.DrawerLayout>
    </fragment>

Any help please regarding combining google map and slide menu

MapsActivity

import android.content.Context;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.CompoundButton;
import android.widget.ListView;
import android.widget.Switch;
import android.widget.TextView;

import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.MarkerOptions;

import java.util.ArrayList;
import java.util.List;

public class MapsActivity extends FragmentActivity {

    private GoogleMap mMap; // Might be null if Google Play services APK is not available.

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_maps);
        ListView drawerView = (ListView) findViewById(R.id.left_drawer);

        List<String> switches = new ArrayList<String>();
        switches.add("Switch 1");
        switches.add("Switch 2");
        switches.add("Switch 3");

        ListAdapter adapter = new ListAdapter(this, R.layout.itemlistrow, switches);
        drawerView.setAdapter(adapter);
    }

    @Override
    protected void onResume() {
        super.onResume();
        setUpMapIfNeeded();
    }

    /**
     * Sets up the map if it is possible to do so (i.e., the Google Play services APK is correctly
     * installed) and the map has not already been instantiated.. This will ensure that we only ever
     * call {@link #setUpMap()} once when {@link #mMap} is not null.
     * <p/>
     * If it isn't installed {@link SupportMapFragment} (and
     * {@link com.google.android.gms.maps.MapView MapView}) will show a prompt for the user to
     * install/update the Google Play services APK on their device.
     * <p/>
     * A user can return to this FragmentActivity after following the prompt and correctly
     * installing/updating/enabling the Google Play services. Since the FragmentActivity may not
     * have been completely destroyed during this process (it is likely that it would only be
     * stopped or paused), {@link #onCreate(Bundle)} may not be called again so we should call this
     * method in {@link #onResume()} to guarantee that it will be called.
     */
    private void setUpMapIfNeeded() {
        // Do a null check to confirm that we have not already instantiated the map.
        if (mMap == null) {
            // Try to obtain the map from the SupportMapFragment.
            mMap = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map))
                    .getMap();
            // Check if we were successful in obtaining the map.
            if (mMap != null) {
                setUpMap();
            }
        }
    }

    /**
     * This is where we can add markers or lines, add listeners or move the camera. In this case, we
     * just add a marker near Africa.
     * <p/>
     * This should only be called once and when we are sure that {@link #mMap} is not null.
     */
    private void setUpMap() {
        mMap.addMarker(new MarkerOptions().position(new LatLng(0, 0)).title("Marker"));
    }

    public class ListAdapter extends ArrayAdapter<String> {
        public ListAdapter(Context context, int textViewResourceId) {
            super(context, textViewResourceId);
        }

        public ListAdapter(Context context, int resource, List<String> items) {
            super(context, resource, items);
        }

        @Override
        public View getView(final int position, View convertView, ViewGroup parent) {
            View v = convertView;

            if (v == null) {
                LayoutInflater vi;
                vi = LayoutInflater.from(getContext());
                v = vi.inflate(R.layout.itemlistrow, null);
            }

            String p = getItem(position);

            if (p != null) {
                TextView tt1 = (TextView) v.findViewById(R.id.name);
                Switch switchI = (Switch) v.findViewById(R.id.value);

                if (tt1 != null) {
                    tt1.setText(p);
                }

                switchI.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
                    public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                        switch (position) {
                            case 1:
                                // TODO: Behaviour of switchI on first row
                                break;
                            case 2:
                                // TODO: Behaviour of switchI on second row
                                break;
                            default:
                                // TODO: Default behaviour
                                break;
                        }
                    }
                });
            }
            return v;
        }
    }
}

activity-maps.xml

<android.support.v4.widget.DrawerLayout
    android:layout_height="match_parent"
    android:layout_width="match_parent"
    android:id="@+id/drawer_layout"
    xmlns:android="http://schemas.android.com/apk/res/android">

    <!-- As the main content view, the view below consumes the entire space available using match_parent in both dimensions. -->


    <FrameLayout android:layout_height="match_parent" android:layout_width="match_parent" android:id="@+id/content_frame"/>

    <!-- android:layout_gravity="start" tells DrawerLayout to treat this as a sliding drawer on the left side for left-to-right languages and on the right side for right-to-left languages. The drawer is given a fixed width in dp and extends the full height of the container. A solid background is used for contrast with the content view. -->
    <ListView
        android:layout_height="match_parent"
        android:layout_width="140dp"
        android:id="@+id/left_drawer"
        android:background="#111"
        android:dividerHeight="0dp"
        android:divider="@android:color/transparent"
        android:choiceMode="singleChoice"
        android:layout_gravity="start"/>
    <fragment
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/map"
    android:name="com.google.android.gms.maps.SupportMapFragment"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.example.hp.fakeyourlocation.map.LocationChooser">

    <Button
        android:layout_width="100dp"
        android:layout_height="70dp"
        android:layout_gravity="center|bottom"
        android:id="@+id/button2"
        android:text="Show my current location"
        android:padding="10dp"/>
    <Switch
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/pocisti"
        android:layout_gravity="left|bottom"
        android:text="Ukloni oznake"
        android:padding="10dp"
        android:layout_marginTop="20dp"
        android:paddingRight="10dp"/>


    </fragment>
    </android.support.v4.widget.DrawerLayout>

itemlistrow.xml

<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal"
    android:paddingBottom="10dp"
    android:paddingLeft="20dp"
    android:paddingRight="20dp"
    android:paddingTop="10dp">

    <TextView
        android:id="@+id/name"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_vertical"
        android:layout_marginRight="15dp"
        android:gravity="center_vertical"
        android:textColor="#fff"/>

    <Switch
        android:id="@+id/value"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:clickable="true"
        android:textColor="#fff"/>

</LinearLayout>
Jure
  • 49
  • 3
  • 7

1 Answers1

0

From the documentation:

To add a navigation drawer, declare your user interface with a DrawerLayout object as the root view of your layout. Inside the DrawerLayout, add one view that contains the main content for the screen (your primary layout when the drawer is hidden) and another view that contains the contents of the navigation drawer.

So, the android.support.v4.widget.DrawerLayout must be the root view (in your case you just have added it at the end of yur existing xml).

This is an example of a working xml with a map and a DrawerLayout :

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout android:id="@+id/drawer_layout" xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent">

    <fragment
        android:id="@+id/map"
        android:name="com.google.android.gms.maps.SupportMapFragment"
        android:layout_width="match_parent"
        android:layout_height="match_parent"/>

    <ListView
        android:id="@+id/left_drawer"
        android:layout_width="300dp"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:choiceMode="singleChoice"
        android:divider="@android:color/transparent"
        android:dividerHeight="0dp"
        android:paddingLeft="10dp"
        android:paddingRight="10dp"/>

</android.support.v4.widget.DrawerLayout>

UPDATE: A simple example using the answer above and the proposed code from Custom Adapter for List View to illustrate the creation of a left drawer with switches:

activity_maps.xml

<android.support.v4.widget.DrawerLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <fragment
        android:id="@+id/map"
        android:name="com.google.android.gms.maps.MapFragment"
        android:layout_width="match_parent"
        android:layout_height="match_parent"/>

    <ListView
        android:id="@+id/left_drawer"
        android:layout_width="300dp"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:background="#000"
        android:choiceMode="singleChoice"
        android:divider="@android:color/transparent"
        android:dividerHeight="0dp"
        android:paddingLeft="10dp"
        android:paddingRight="10dp"/>

</android.support.v4.widget.DrawerLayout>

itemlistrow.xml

<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal"
    android:paddingBottom="10dp"
    android:paddingLeft="20dp"
    android:paddingRight="20dp"
    android:paddingTop="10dp">

    <TextView
        android:id="@+id/name"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_vertical"
        android:layout_marginRight="15dp"
        android:gravity="center_vertical"
        android:textColor="#fff"/>

    <Switch
        android:id="@+id/value"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:clickable="true"
        android:textColor="#fff"/>

</LinearLayout>

MapsActivity.java

public class MapsActivity extends FragmentActivity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_maps);

        ListView drawerView = (ListView) findViewById(R.id.left_drawer);

        List<String> switches = new ArrayList<String>();
        switches.add("Switch 1");
        switches.add("Switch 2");
        switches.add("Switch 3");

        ListAdapter adapter = new ListAdapter(this, R.layout.itemlistrow, switches);
        drawerView.setAdapter(adapter);
    }

    public class ListAdapter extends ArrayAdapter<String> {
        public ListAdapter(Context context, int textViewResourceId) {
            super(context, textViewResourceId);
        }

        public ListAdapter(Context context, int resource, List<String> items) {
            super(context, resource, items);
        }

        @Override
        public View getView(final int position, View convertView, ViewGroup parent) {
            View v = convertView;

            if (v == null) {
                LayoutInflater vi;
                vi = LayoutInflater.from(getContext());
                v = vi.inflate(R.layout.itemlistrow, null);
            }

            String p = getItem(position);

            if (p != null) {
                TextView tt1 = (TextView) v.findViewById(R.id.name);
                Switch switchI = (Switch) v.findViewById(R.id.value);

                if (tt1 != null) {
                    tt1.setText(p);
                }

                switchI.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
                    public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                        switch (position) {
                            case 1:
                                // TODO: Behaviour of switchI on first row
                                break;
                            case 2:
                                // TODO: Behaviour of switchI on second row
                                break;
                            default:
                                // TODO: Default behaviour
                                break;
                        }
                    }
                });
            }
            return v;
        }
    }
}

UPDATE: xml with two switches for each row

itemlistrow.xml

<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal"
    android:paddingBottom="10dp"
    android:paddingLeft="20dp"
    android:paddingRight="20dp"
    android:paddingTop="10dp">

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        android:layout_weight="1">

        <TextView
            android:id="@+id/name"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginRight="15dp"
            android:gravity="center_horizontal"
            android:text="SW1"
            android:textColor="#fff"/>

        <Switch
            android:id="@+id/value"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:clickable="true"
            android:textColor="#fff"/>

    </LinearLayout>

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        android:layout_weight="1">

        <TextView
            android:id="@+id/name2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginRight="15dp"
            android:gravity="center_horizontal"
            android:text="SW2"
            android:textColor="#fff"/>

        <Switch
            android:id="@+id/value2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:clickable="true"
            android:textColor="#fff"/>

    </LinearLayout>

</LinearLayout>

Or alternatively, removing the TextViews and using the text property of the Switch:

<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal"
    android:paddingBottom="10dp"
    android:paddingLeft="20dp"
    android:paddingRight="20dp"
    android:paddingTop="10dp">

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        android:layout_weight="1">

        <Switch
            android:id="@+id/value"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="SW1"
            android:clickable="true"
            android:textColor="#fff"/>

    </LinearLayout>

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        android:layout_weight="1">

        <Switch
            android:id="@+id/value2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="SW2"
            android:clickable="true"
            android:textColor="#fff"/>

    </LinearLayout>

</LinearLayout>

Modifications of MapsActivity to use the two switches on the same row view above (WARNING: NOT FULLY TESTED):

public class MapsActivity extends FragmentActivity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_maps);

        ListView drawerView = (ListView) findViewById(R.id.left_drawer);

        List<RowItem> switches = new ArrayList<RowItem>();
        switches.add(new RowItem("Hotels", "Hostels");
        switches.add(new RowItem("Camps", "Private");

        ListAdapter adapter = new ListAdapter(this, R.layout.itemlistrow, switches);
        drawerView.setAdapter(adapter);
    }

    public class ListAdapter extends ArrayAdapter<RowItem> {
        public ListAdapter(Context context, int textViewResourceId) {
            super(context, textViewResourceId);
        }

        public ListAdapter(Context context, int resource, List<RowItem> items) {
            super(context, resource, items);
        }

        @Override
        public View getView(final int position, View convertView, ViewGroup parent) {
            View v = convertView;

            if (v == null) {
                LayoutInflater vi;
                vi = LayoutInflater.from(getContext());
                v = vi.inflate(R.layout.itemlistrow, null);
            }

            RowItem p = getItem(position);

            if (p != null) {
                TextView tt1 = (TextView) v.findViewById(R.id.name);
                Switch switchI1 = (Switch) v.findViewById(R.id.value);
                TextView tt2 = (TextView) v.findViewById(R.id.name2);
                Switch switchI2 = (Switch) v.findViewById(R.id.value2);

                tt1.setText(p.getSwitch1Name());
                tt2.setText(p.getSwitch2Name());

                switchI1.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
                    public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                        switch (position) {
                            case 0:
                                // TODO: Behaviour of switchI1 on first row
                                break;
                            case 1:
                                // TODO: Behaviour of switchI1 on second row
                                break;
                            default:
                                // TODO: Default behaviour
                                break;
                        }
                    }
                });

                switchI2.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
                    public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                        switch (position) {
                            case 0:
                                // TODO: Behaviour of switchI2 on first row
                                break;
                            case 1:
                                // TODO: Behaviour of switchI2 on second row
                                break;
                            default:
                                // TODO: Default behaviour
                                break;
                        }
                    }
                });
            }
            return v;
        }
    }

    private class RowItem {
        private String switch1Name;
        private String switch2Name;

        public RowItem(String switch1Name, String switch2Name) {
            this.switch1Name = switch1Name;
            this.switch2Name = switch2Name;
        }

        public String getSwitch1Name() {
            return switch1Name;
        }

        public String getSwitch2Name() {
            return switch2Name;
        }
    }
}
Community
  • 1
  • 1
antonio
  • 18,044
  • 4
  • 45
  • 61
  • Great thanks. Can you let me know how to out switches inside this slide menu? – Jure Oct 21 '15 at 10:06
  • @Jure, to put switches, or images, or complex layouts inside the drawer, you will need to add a custom adapter to the ListView (left_drawer in my example). You can take a look at http://stackoverflow.com/questions/8166497/custom-adapter-for-list-view – antonio Oct 21 '15 at 10:14
  • Any chance you could paste your code and how it is connected to main activity? – Jure Oct 21 '15 at 10:53
  • Works like a charm...Just one more question, can you let me know how to organise switches in the menu so there are two of them in each row? – Jure Oct 21 '15 at 11:40
  • @Jure easy, just modify itemlistrow.xml to adapt it to your needs, adding another `TextView` and another `Switch`, and manage the new components in the `getView` method – antonio Oct 21 '15 at 11:52
  • Also @Antonio, please let me know how can I access activity (isChecked) of each switch in the MapsActivity? How do I set id for each switch? – Jure Oct 21 '15 at 11:55
  • @Jure In my example, there is a `//TODO: Do something with the switch`. There, you can do `switchI.isChecked();` or `switchI.setChecked(true);` (for example) – antonio Oct 21 '15 at 11:58
  • Antonio, i did...This is the code I added at TODO part if(switchI.isChecked()){ Toast.makeText(getApplicationContext(), switchI.getText(), Toast.LENGTH_SHORT).show(); } but nothing happens when I click on switch – Jure Oct 21 '15 at 12:06
  • @Jure, yep, my mistake, you need to attach a `OnCheckedChangeListener` to your switch. Take a look at http://stackoverflow.com/questions/11278507/android-widget-switch-on-off-event-listener – antonio Oct 21 '15 at 12:11
  • I'm no really sure how this works? In the itemlistrow.xml there is only one Switch with id "value". In Main class you declare 3 switches so I'm not sure how can I access each one of them, since they should be having different "jobs" TO DO? – Jure Oct 21 '15 at 12:18
  • Any solution here Antonio? – Jure Oct 21 '15 at 12:39
  • @Jure of course there are solutions! In the itemlistrow.xml there is only one Switch because thid xml is the template that you inflate to create each view. You need to do something different based on the `position` you receive in the `getView` method – antonio Oct 21 '15 at 12:59
  • OK, but can you specify the place I should attach OnCheckedChangeListener and where should I manage the TODO for each Switch? – Jure Oct 21 '15 at 13:13
  • I'm not sure on where to specify OnCheckedChangeListener and how to get action from each Switch in the Main activity? – Jure Oct 21 '15 at 13:55
  • I have changed ListAdapter class but Switches are still "dead" nothing happens when clicked. I added this code to TO DOcase 1: Toast.makeText(getApplicationContext(), "Test1", Toast.LENGTH_SHORT).show(); break; case 2: Toast.makeText(getApplicationContext(), "Test2", Toast.LENGTH_SHORT).show(); break; – Jure Oct 21 '15 at 14:17
  • I guess I'm making some trivial mistake, but cannot get it – Jure Oct 21 '15 at 14:28
  • I have tested my example and it's working as expected, could you post your code? – antonio Oct 21 '15 at 14:31
  • Take into account that position starts with 0, try adding a Toast on the default behaviour to see if the problem is that the switch/case goes throught default – antonio Oct 21 '15 at 14:43
  • I tried, added Toast to all options (and default) but nothing happens. Like Switch doesn't react on click at all (slide manu does close on click)..I have no idea what's the problem – Jure Oct 21 '15 at 14:47
  • I don't see anything strange, have you tested my code in a project created from scratch to see if the problem is in the device you are executing it? – antonio Oct 21 '15 at 16:30
  • I did, nothing happens. Using Sony Z3...Not sure what to try anymore – Jure Oct 21 '15 at 17:54
  • I tried running your code from clean but AS emulator is giving me error "App will not start until you upgrade your GooglePlay". My code is working but I canot click on any Switch. – Jure Oct 21 '15 at 19:26
  • I have successfully run the example in two physical devices and on the emulator. Maybe you should post another question. You can use the code as a minimal, complete, and verifiable example. – antonio Oct 22 '15 at 06:14
  • I will antonio. I'll start from scratch now again using your code. Can you post methods you are using to present markers on a map? My final idea is to present different markers on the map depending on which switch is turned on. – Jure Oct 22 '15 at 07:48
  • @Antonio..I tried from scratch using your code and it crashes in emulator with error java.lang.RuntimeException: Unable to resume activity {com.example.jc.antoniotest/com.example.jc.antoniotest.MapsActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'com.google.android.gms.maps.GoogleMap com.google.android.gms.maps.SupportMapFragment.getMap()' on a null object reference.....Any idea what is going on? – Jure Oct 22 '15 at 08:10
  • Simply use the `GoogleMap.addMarker(markerOptions)` method (https://developers.google.com/maps/documentation/android-api/marker). In your case for example you can do something like mMap.addMarker(new MarkerOptions().position(new LatLng(10, 10)).title("Hello world")); (Assuming your nMap object has been initialized). – antonio Oct 22 '15 at 08:11
  • I edited Main activity in the question...It is same as yours I believe – Jure Oct 22 '15 at 08:31
  • But you have added more code because the error is happening in a call to `getMap()` that was not in my original code – antonio Oct 22 '15 at 08:38
  • I tried your code now (without getMap) and in the emulator I get an message (Aplication won't run unless you update your Google Play service)? On the device it starts normaly. – Jure Oct 22 '15 at 08:45
  • What API are you using? – Jure Oct 22 '15 at 08:52
  • Take a look at http://stackoverflow.com/questions/30165458/can-not-run-google-play-service-on-emulator-need-to-update-google-play-service – antonio Oct 22 '15 at 09:00
  • @Antonio..Which API are you using in your version? I cannot set API level on emulator to less then 23 – Jure Oct 22 '15 at 09:09
  • I'm compiling against version 14 and executing in a API 22 emulator – antonio Oct 22 '15 at 09:17
  • I started new one with API 14 and still getting the error in the emulator that I need to update GooglePlay services...Really do not know how to go anywhere from here – Jure Oct 22 '15 at 09:46
  • Any suggestions antonio? – Jure Oct 22 '15 at 10:19
  • Can you edit your code to present one static marker on a map after you check one switch? – Jure Oct 22 '15 at 11:04
  • i got it working finally!! Can you just let me know how can have 2 switches in each row in the slide menu? Thanks a lot! – Jure Oct 22 '15 at 11:51
  • I've been out of my computer for a while. What was the problem? I will add the new layout with two switches asap – antonio Oct 22 '15 at 12:31
  • The problem was I used android:id="@+id/map" android:name="com.google.android.gms.maps.MapFragment" instead of "com.google.android.gms.maps.SupportMapFragment – Jure Oct 22 '15 at 12:48
  • Please let me know when you edit the layout with two switches in each row – Jure Oct 22 '15 at 12:58
  • @Jure I have added the new xml – antonio Oct 22 '15 at 14:10
  • I tired but it just lists Switches one bellow other in groups of two. What i wanted is to have to Switches in on line and lines till the end of the screen. So I could actually have 10-15 rows each having 2 svitches. Is that possible? – Jure Oct 22 '15 at 14:37
  • I think I don't understand what you need... could you explain? – antonio Oct 22 '15 at 15:09
  • Hi Antonio, now switches are listed one bellow another, one in each line...I would like to have a posibility to have two switches in one line – Jure Oct 22 '15 at 17:48
  • You know what I mean? – Jure Oct 22 '15 at 17:54
  • @Jure I think I understood, check now. Anyway, you should take a look at Android's layout documentation: http://developer.android.com/guide/topics/ui/layout/linear.html – antonio Oct 22 '15 at 18:05
  • @Jure itemlistrow.xml. And I have added a second alternative to use the `text` property of the `Switch` to avoid the `TextView` and the inner `LinearLayout`s – antonio Oct 22 '15 at 18:14
  • Positions to identify switch that was clicked are some as before?0,1,2,3,4...? – Jure Oct 22 '15 at 18:20
  • Positions will be 0, 1, 2... for each row, but you will need need to modify the `getView` method because now the first `Switch` of each row will be `value` and the second will be `value2`. For example: `Switch switchI2 = (Switch) v.findViewById(R.id.value2); ` – antonio Oct 22 '15 at 18:23
  • I tried the first option and put 4 switches switches.add("Hotels"); switches.add("Hostels"); switches.add("Camps"); switches.add("Private"); but they are not presented like they should. In the first line I have Hotels and SW2, second line Hostels and SW2....It Should be 1.line Hotels Hostels, 2 line Camps Private – Jure Oct 22 '15 at 18:34
  • Can you edit the code? I'm not sure if I need to have 2 types of switches now (switch1 and switch2) and how their positions are going to count? – Jure Oct 22 '15 at 18:46
  • I have updated my code, but I'm on a different computer and I couldn't test it, so maybe there are some minor errors (easy to solve I hope). Anyway, all the problems that you are facing on this question are Layout related. You **need** to learn about Layouts and about ListViews. It will help you a lot on future development – antonio Oct 22 '15 at 19:11
  • Thanks Antonio, sorry for bothering you so much – Jure Oct 22 '15 at 19:21
  • I'm glad to help, I'm just trying to point you in the right direction so you can improve your Android and Google Maps development. Keep up the effort! – antonio Oct 22 '15 at 19:33
  • Thanks again, I will deal with this latter, another problem, my Retofit part stopped working again – Jure Oct 22 '15 at 19:36
  • OK, let me know how this ends ;) – antonio Oct 22 '15 at 19:44
  • Do you maybe have a version itemlistrow.xml from before I asked your for multiple switches in line? – Jure Oct 22 '15 at 20:18
  • Right below the answer there is a link "edited...". If you click there you will see the editions made – antonio Oct 22 '15 at 20:28
  • My Retrofit part blew away after I made the changes in itemlistrow.xml (not sure how is this related) – Jure Oct 22 '15 at 20:28
  • If you have an idea...http://stackoverflow.com/questions/33291102/expected-begin-array-but-was-string-at-line-2-column-11 – Jure Oct 22 '15 at 21:38