Android谷歌地图不使用幻灯片菜单
我有一个应用程序,它使用gmap从webservice获取标记并在地图上显示。 这是非常有效的布局代码Android谷歌地图不使用幻灯片菜单,android,google-maps,drawerlayout,Android,Google Maps,Drawerlayout,我有一个应用程序,它使用gmap从webservice获取标记并在地图上显示。 这是非常有效的布局代码 <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
<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>
我想添加到幻灯片菜单,而不是主屏幕中的开关。一旦我将幻灯片菜单的代码添加到此文件的末尾,我就可以看到幻灯片菜单,但谷歌地图停止工作。这是不起作用的新代码
<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>
关于组合谷歌地图和幻灯片菜单,请提供任何帮助
地图活性
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;
}
}
}
导入android.content.Context;
导入android.os.Bundle;
导入android.support.v4.app.FragmentActivity;
导入android.view.LayoutInflater;
导入android.view.view;
导入android.view.ViewGroup;
导入android.widget.ArrayAdapter;
导入android.widget.CompoundButton;
导入android.widget.ListView;
导入android.widget.Switch;
导入android.widget.TextView;
导入com.google.android.gms.maps.GoogleMap;
导入com.google.android.gms.maps.SupportMapFragment;
导入com.google.android.gms.maps.model.LatLng;
导入com.google.android.gms.maps.model.MarkerOptions;
导入java.util.ArrayList;
导入java.util.List;
公共类映射活动扩展了FragmentActivity{
私有GoogleMap mMap;//如果Google Play services APK不可用,则可能为空。
@凌驾
创建时受保护的void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_映射);
ListView抽屉视图=(ListView)findViewById(R.id.left\u抽屉);
列表开关=新的ArrayList();
开关。添加(“开关1”);
开关。添加(“开关2”);
开关。添加(“开关3”);
ListAdapter=新的ListAdapter(此,R.layout.itemlistrow,开关);
抽屉视图设置适配器(适配器);
}
@凌驾
受保护的void onResume(){
super.onResume();
setupmapifneed();
}
/**
*如果可能的话,设置地图(例如,Google Play services APK已正确启动)
*已安装)并且映射尚未实例化。这将确保
*当{@link#mMap}不为null时,调用{@link#setUpMap()}一次。
*
*如果未安装{@link SupportMapFragment}(和
*{@link com.google.android.gms.maps.MapView MapView})将提示用户
*在其设备上安装/更新Google Play services APK。
*
*用户可以按照提示正确返回此FragmentActivity
*安装/更新/启用Google Play服务。因为碎片活动可能不会
*在这一过程中被完全破坏(很可能
*停止或暂停),{@link#onCreate(Bundle)}可能不会被再次调用,因此我们应该调用它
*方法来保证将调用它。
*/
私有void setUpMapIfNeeded(){
//执行空检查以确认尚未实例化映射。
如果(mMap==null){
//尝试从SupportMapFragment获取映射。
mMap=((SupportMapFragment)getSupportFragmentManager().findFragmentById(R.id.map))
.getMap();
//检查我们是否成功获得地图。
如果(mMap!=null){
setUpMap();
}
}
}
/**
*在这里,我们可以添加标记或线条、添加侦听器或移动摄影机
*在非洲附近加一个标记。
*
*当我们确定{@link#mMap}不是null时,应该只调用一次。
*/
私有void setUpMap(){
mMap.addMarker(新的MarkerOptions().position(新的LatLng(0,0)).title(“Marker”);
}
公共类ListAdapter扩展了ArrayAdapter{
公共ListAdapter(上下文上下文,int textViewResourceId){
super(上下文,textViewResourceId);
}
公共ListAdapter(上下文上下文、int资源、列表项){
超级(上下文、资源、项目);
}
@凌驾
公共视图getView(最终整数位置、视图转换视图、视图组父视图){
视图v=转换视图;
如果(v==null){
拉平机vi;
vi=LayoutInflater.from(getContext());
v=vi.充气(R.layout.itemlistrow,空);
}
字符串p=getItem(位置);
如果(p!=null){
TextView tt1=(TextView)v.findViewById(R.id.name);
开关switchI=(开关)v.findViewById(R.id.value);
如果(tt1!=null){
tt1.setText(p);
}
setOnCheckedChangeListener(新的CompoundButton.OnCheckedChangeListener(){
检查更改后的公共无效(复合按钮视图,布尔值已检查){
开关(位置){
案例1:
//TODO:第一行开关的行为
打破
案例2:
//TODO:第二排switchI的行为
打破
违约:
//TODO:默认行为
打破
}
}
});
}
返回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>
来自:
要添加导航抽屉,请声明您的
<?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>
<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>
<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>
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;
}
}
}
<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>
<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>
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;
}
}
}