android 应用之listview添加radiobutton
程序效果:
点击一整行,更换radiobutton选择。
xml代码:
view plaincopy to clipboardprint?
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/layout"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView android:id="@+id/list_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
/>
<ImageView android:id="@+id/list_radioImg"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"/>
</RelativeLayout>
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/layout"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView android:id="@+id/list_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
/>
<ImageView android:id="@+id/list_radioImg"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"/>
</RelativeLayout>
java代码:
view plaincopy to clipboardprint?
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import android.app.ListActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import android.widget.Toast;
public class listRadioBtn extends ListActivity {
/** Called when the activity is first created. */
private int balanceIndex = 0;
SimpleAdapter adapter;
List<Map<String, Object>> list;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
adapter= new SimpleAdapter(this,getData(),R.layout.main,new String[]{"text","img"},new int[]{R.id.list_text,R.id.list_radioImg});
setListAdapter(adapter);
}
private List<Map<String, Object>> getData(){
list = new ArrayList<Map<String, Object>>();
Map<String, Object> map_day = new HashMap<String, Object>();
map_day.put("text", "白天");
map_day.put("img", R.drawable.setlist_radio_on);
list.add(map_day);
Map<String, Object> map_clody = new HashMap<String, Object>();
map_clody.put("text", "阴天");
map_clody.put("img", R.drawable.setlist_radio_off);
list.add(map_clody);
Map<String, Object> map_clo = new HashMap<String, Object>();
map_clo.put("text", "微风");
map_clo.put("img", R.drawable.setlist_radio_off);
list.add(map_clo);
return list;
}
protected void onListItemClick(ListView arg0, View arg1, int arg2, long arg3) {
Toast t = Toast.makeText(this, ""+list.get(arg2).get("text"), Toast.LENGTH_LONG);
t.show();
ChangeRadioImg(balanceIndex,false);
ChangeRadioImg(arg2,true);
balanceIndex=arg2;
list.get(arg2).get("text");
}
private void ChangeRadioImg(int selectedItem, boolean b) {
SimpleAdapter la = adapter;
HashMap<String, Object> map = (HashMap<String, Object>)la.getItem(selectedItem);
if(b)
map.put("img", R.drawable.setlist_radio_on);
else
map.put("img", R.drawable.setlist_radio_off);
la.notifyDataSetChanged();
}
}
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import android.app.ListActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import android.widget.Toast;
public class listRadioBtn extends ListActivity {
/** Called when the activity is first created. */
private int balanceIndex = 0;
SimpleAdapter adapter;
List<Map<String, Object>> list;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
adapter= new SimpleAdapter(this,getData(),R.layout.main,new String[]{"text","img"},new int[]{R.id.list_text,R.id.list_radioImg});
setListAdapter(adapter);
}
private List<Map<String, Object>> getData(){
list = new ArrayList<Map<String, Object>>();
Map<String, Object> map_day = new HashMap<String, Object>();
map_day.put("text", "白天");
map_day.put("img", R.drawable.setlist_radio_on);
list.add(map_day);
Map<String, Object> map_clody = new HashMap<String, Object>();
map_clody.put("text", "阴天");
map_clody.put("img", R.drawable.setlist_radio_off);
list.add(map_clody);
Map<String, Object> map_clo = new HashMap<String, Object>();
map_clo.put("text", "微风");
map_clo.put("img", R.drawable.setlist_radio_off);
list.add(map_clo);
return list;
}
protected void onListItemClick(ListView arg0, View arg1, int arg2, long arg3) {
Toast t = Toast.makeText(this, ""+list.get(arg2).get("text"), Toast.LENGTH_LONG);
t.show();
ChangeRadioImg(balanceIndex,false);
ChangeRadioImg(arg2,true);
balanceIndex=arg2;
list.get(arg2).get("text");
}
private void ChangeRadioImg(int selectedItem, boolean b) {
SimpleAdapter la = adapter;
HashMap<String, Object> map = (HashMap<String, Object>)la.getItem(selectedItem);
if(b)
map.put("img", R.drawable.setlist_radio_on);
else
map.put("img", R.drawable.setlist_radio_off);
la.notifyDataSetChanged();
}
}
二
另一个简单办法:
android系统中,提供了这样的方法
mylist.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
程序主代码:
view plaincopy to clipboardprint?
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.list_layout);
contentString = new String[] {
"示例", "透明动画",
"伸缩动画", "移动动画",
"旋转动画", "透明_伸缩",
"透明_移动", "透明_旋转"
};
arrayAdapter = new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_single_choice,
contentString);
mylist = (ListView) findViewById(R.id.ListView01);
mylist.setAdapter(arrayAdapter);
mylist.setOnItemClickListener(this);
mylist.setOnItemSelectedListener(this);
mylist.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
mylist.setItemChecked(0, true);
}
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.list_layout);
contentString = new String[] {
"示例", "透明动画",
"伸缩动画", "移动动画",
"旋转动画", "透明_伸缩",
"透明_移动", "透明_旋转"
};
arrayAdapter = new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_single_choice,
contentString);
mylist = (ListView) findViewById(R.id.ListView01);
mylist.setAdapter(arrayAdapter);
mylist.setOnItemClickListener(this);
mylist.setOnItemSelectedListener(this);
mylist.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
mylist.setItemChecked(0, true);
}
其中,android.R.layout.simple_list_item_single_choice在framework/base/core/res/res/layout目录下,可参见源码
三 多选框
view plaincopy to clipboardprint?
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.ArrayAdapter;
import android.widget.ListView;
public class ListCheckbox extends Activity implements OnItemClickListener,OnItemSelectedListener{
private String contentString[];
ArrayAdapter arrayAdapter;
ListView mylist;
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
contentString = new String[] {
"示例", "透明动画",
"伸缩动画", "移动动画",
"旋转动画", "透明_伸缩",
"透明_移动", "透明_旋转"
};
arrayAdapter = new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_multiple_choice,//.simple_list_item_single_choice,
contentString);
mylist = (ListView) findViewById(R.id.ListView01);
mylist.setAdapter(arrayAdapter);
mylist.setOnItemClickListener(this);
mylist.setOnItemSelectedListener(this);
mylist.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);//.CHOICE_MODE_SINGLE);
mylist.setItemChecked(0, true);
}
public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2,long arg3) {
mylist.setItemChecked(arg2, true);
}
public void onNothingSelected(AdapterView<?> arg0) {
// TODO Auto-generated method stub
}
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
// TODO Auto-generated method stub
}
}
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.ArrayAdapter;
import android.widget.ListView;
public class ListCheckbox extends Activity implements OnItemClickListener,OnItemSelectedListener{
private String contentString[];
ArrayAdapter arrayAdapter;
ListView mylist;
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
contentString = new String[] {
"示例", "透明动画",
"伸缩动画", "移动动画",
"旋转动画", "透明_伸缩",
"透明_移动", "透明_旋转"
};
arrayAdapter = new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_multiple_choice,//.simple_list_item_single_choice,
contentString);
mylist = (ListView) findViewById(R.id.ListView01);
mylist.setAdapter(arrayAdapter);
mylist.setOnItemClickListener(this);
mylist.setOnItemSelectedListener(this);
mylist.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);//.CHOICE_MODE_SINGLE);
mylist.setItemChecked(0, true);
}
public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2,long arg3) {
mylist.setItemChecked(arg2, true);
}
public void onNothingSelected(AdapterView<?> arg0) {
// TODO Auto-generated method stub
}
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
// TODO Auto-generated method stub
}
}
main.xml
view plaincopy to clipboardprint?
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<ListView android:id="@+id/ListView01"
android:layout_width="fill_parent"
android:layout_height="fill_parent"/>
</LinearLayout>
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<ListView android:id="@+id/ListView01"
android:layout_width="fill_parent"
android:layout_height="fill_parent"/>
</LinearLayout>
程序效果:

点击一整行,更换radiobutton选择。
xml代码:
view plaincopy to clipboardprint?
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/layout"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView android:id="@+id/list_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
/>
<ImageView android:id="@+id/list_radioImg"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"/>
</RelativeLayout>
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/layout"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView android:id="@+id/list_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
/>
<ImageView android:id="@+id/list_radioImg"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"/>
</RelativeLayout>
java代码:
view plaincopy to clipboardprint?
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import android.app.ListActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import android.widget.Toast;
public class listRadioBtn extends ListActivity {
/** Called when the activity is first created. */
private int balanceIndex = 0;
SimpleAdapter adapter;
List<Map<String, Object>> list;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
adapter= new SimpleAdapter(this,getData(),R.layout.main,new String[]{"text","img"},new int[]{R.id.list_text,R.id.list_radioImg});
setListAdapter(adapter);
}
private List<Map<String, Object>> getData(){
list = new ArrayList<Map<String, Object>>();
Map<String, Object> map_day = new HashMap<String, Object>();
map_day.put("text", "白天");
map_day.put("img", R.drawable.setlist_radio_on);
list.add(map_day);
Map<String, Object> map_clody = new HashMap<String, Object>();
map_clody.put("text", "阴天");
map_clody.put("img", R.drawable.setlist_radio_off);
list.add(map_clody);
Map<String, Object> map_clo = new HashMap<String, Object>();
map_clo.put("text", "微风");
map_clo.put("img", R.drawable.setlist_radio_off);
list.add(map_clo);
return list;
}
protected void onListItemClick(ListView arg0, View arg1, int arg2, long arg3) {
Toast t = Toast.makeText(this, ""+list.get(arg2).get("text"), Toast.LENGTH_LONG);
t.show();
ChangeRadioImg(balanceIndex,false);
ChangeRadioImg(arg2,true);
balanceIndex=arg2;
list.get(arg2).get("text");
}
private void ChangeRadioImg(int selectedItem, boolean b) {
SimpleAdapter la = adapter;
HashMap<String, Object> map = (HashMap<String, Object>)la.getItem(selectedItem);
if(b)
map.put("img", R.drawable.setlist_radio_on);
else
map.put("img", R.drawable.setlist_radio_off);
la.notifyDataSetChanged();
}
}
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import android.app.ListActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import android.widget.Toast;
public class listRadioBtn extends ListActivity {
/** Called when the activity is first created. */
private int balanceIndex = 0;
SimpleAdapter adapter;
List<Map<String, Object>> list;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
adapter= new SimpleAdapter(this,getData(),R.layout.main,new String[]{"text","img"},new int[]{R.id.list_text,R.id.list_radioImg});
setListAdapter(adapter);
}
private List<Map<String, Object>> getData(){
list = new ArrayList<Map<String, Object>>();
Map<String, Object> map_day = new HashMap<String, Object>();
map_day.put("text", "白天");
map_day.put("img", R.drawable.setlist_radio_on);
list.add(map_day);
Map<String, Object> map_clody = new HashMap<String, Object>();
map_clody.put("text", "阴天");
map_clody.put("img", R.drawable.setlist_radio_off);
list.add(map_clody);
Map<String, Object> map_clo = new HashMap<String, Object>();
map_clo.put("text", "微风");
map_clo.put("img", R.drawable.setlist_radio_off);
list.add(map_clo);
return list;
}
protected void onListItemClick(ListView arg0, View arg1, int arg2, long arg3) {
Toast t = Toast.makeText(this, ""+list.get(arg2).get("text"), Toast.LENGTH_LONG);
t.show();
ChangeRadioImg(balanceIndex,false);
ChangeRadioImg(arg2,true);
balanceIndex=arg2;
list.get(arg2).get("text");
}
private void ChangeRadioImg(int selectedItem, boolean b) {
SimpleAdapter la = adapter;
HashMap<String, Object> map = (HashMap<String, Object>)la.getItem(selectedItem);
if(b)
map.put("img", R.drawable.setlist_radio_on);
else
map.put("img", R.drawable.setlist_radio_off);
la.notifyDataSetChanged();
}
}
二
另一个简单办法:
android系统中,提供了这样的方法
mylist.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
程序主代码:
view plaincopy to clipboardprint?
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.list_layout);
contentString = new String[] {
"示例", "透明动画",
"伸缩动画", "移动动画",
"旋转动画", "透明_伸缩",
"透明_移动", "透明_旋转"
};
arrayAdapter = new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_single_choice,
contentString);
mylist = (ListView) findViewById(R.id.ListView01);
mylist.setAdapter(arrayAdapter);
mylist.setOnItemClickListener(this);
mylist.setOnItemSelectedListener(this);
mylist.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
mylist.setItemChecked(0, true);
}
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.list_layout);
contentString = new String[] {
"示例", "透明动画",
"伸缩动画", "移动动画",
"旋转动画", "透明_伸缩",
"透明_移动", "透明_旋转"
};
arrayAdapter = new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_single_choice,
contentString);
mylist = (ListView) findViewById(R.id.ListView01);
mylist.setAdapter(arrayAdapter);
mylist.setOnItemClickListener(this);
mylist.setOnItemSelectedListener(this);
mylist.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
mylist.setItemChecked(0, true);
}
其中,android.R.layout.simple_list_item_single_choice在framework/base/core/res/res/layout目录下,可参见源码
三 多选框
view plaincopy to clipboardprint?
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.ArrayAdapter;
import android.widget.ListView;
public class ListCheckbox extends Activity implements OnItemClickListener,OnItemSelectedListener{
private String contentString[];
ArrayAdapter arrayAdapter;
ListView mylist;
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
contentString = new String[] {
"示例", "透明动画",
"伸缩动画", "移动动画",
"旋转动画", "透明_伸缩",
"透明_移动", "透明_旋转"
};
arrayAdapter = new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_multiple_choice,//.simple_list_item_single_choice,
contentString);
mylist = (ListView) findViewById(R.id.ListView01);
mylist.setAdapter(arrayAdapter);
mylist.setOnItemClickListener(this);
mylist.setOnItemSelectedListener(this);
mylist.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);//.CHOICE_MODE_SINGLE);
mylist.setItemChecked(0, true);
}
public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2,long arg3) {
mylist.setItemChecked(arg2, true);
}
public void onNothingSelected(AdapterView<?> arg0) {
// TODO Auto-generated method stub
}
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
// TODO Auto-generated method stub
}
}
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.ArrayAdapter;
import android.widget.ListView;
public class ListCheckbox extends Activity implements OnItemClickListener,OnItemSelectedListener{
private String contentString[];
ArrayAdapter arrayAdapter;
ListView mylist;
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
contentString = new String[] {
"示例", "透明动画",
"伸缩动画", "移动动画",
"旋转动画", "透明_伸缩",
"透明_移动", "透明_旋转"
};
arrayAdapter = new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_multiple_choice,//.simple_list_item_single_choice,
contentString);
mylist = (ListView) findViewById(R.id.ListView01);
mylist.setAdapter(arrayAdapter);
mylist.setOnItemClickListener(this);
mylist.setOnItemSelectedListener(this);
mylist.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);//.CHOICE_MODE_SINGLE);
mylist.setItemChecked(0, true);
}
public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2,long arg3) {
mylist.setItemChecked(arg2, true);
}
public void onNothingSelected(AdapterView<?> arg0) {
// TODO Auto-generated method stub
}
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
// TODO Auto-generated method stub
}
}
main.xml
view plaincopy to clipboardprint?
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<ListView android:id="@+id/ListView01"
android:layout_width="fill_parent"
android:layout_height="fill_parent"/>
</LinearLayout>
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<ListView android:id="@+id/ListView01"
android:layout_width="fill_parent"
android:layout_height="fill_parent"/>
</LinearLayout>
发表评论
-
startActivityForResult 简介
2011-03-29 15:55 1284依次打开Activity A1--A2--A3--A4 这时 ... -
startActivityForResult
2011-03-29 15:49 1146startActivityForResult 方法-- ... -
史上最全的Android的Tab与TabHost讲解
2011-03-28 11:22 1591Tab与TabHost 这就是Tab,而盛放Tab的 ... -
Android对话框
2011-03-25 11:21 1125Android 对话框(Dialog)大全 ... -
PreferenceActivity详解
2011-03-25 11:15 1442为了引入这个概率 首先从需求说起 即:现有某Activity专 ... -
TCP/UDP/HTTP
2011-03-25 11:09 1125先来一个讲TCP、UDP和HTTP ... -
9png
2011-03-25 11:08 1914今天学习了用9png图来优化横屏竖屏的UI,使用sdk自带的工 ... -
Notification
2011-03-25 11:07 939Android系统的状态栏(Status Bar)中有一个创新 ... -
一些技巧
2011-03-25 11:03 7871:查看是否有存储卡插入 String status=Envi ... -
布局像素单位
2011-03-25 11:03 827Android的layout文件中有时候可能会指定具体的单位, ... -
使用ActivityGroup来切换Activity和Layout
2011-03-25 11:02 1135在一个主界面中做Activity切换一般都会用TabActiv ... -
activitygroup
2011-03-25 11:01 1730说说tabhost和activitygroup 最近 ... -
线程
2011-03-25 11:01 1014今天在论坛上看到一些关于线程的帖子,我觉得与我理解的有些差异, ... -
类级框架
2011-03-25 11:00 744类集框架:Collection,Map,Iterator,En ... -
Intent打电话
2011-03-25 11:00 1217intent英文意思是意图,pending表示即将发生或来临的 ... -
Intent Uri
2011-03-25 10:59 1068进入联系人页面 1.Intent intent = new I ... -
Service
2011-03-25 10:59 940一、Service的概念 Service是Android程序中 ... -
Broadcast Receiver
2011-03-25 10:56 1948一、Broadcast Receiver简介 Android中 ... -
ContentProvider MIME类型
2011-03-25 10:55 1238Android程序的主要4部分 ... -
ContentProvider-1查询
2011-03-25 10:55 1237今天看了android的官方文档中ContentProvide ...
相关推荐
在Android开发中,自定义的ListView结合RadioButton显示对话框列表数据是一种常见的用户界面设计,用于在弹出的对话框中展示一系列可选的列表项。这样的设计能够为用户提供清晰的选择方式,同时保持屏幕的整洁。以下...
为了在ListView中添加Checkbox和RadioButton,我们需要创建一个自定义的Adapter,例如继承自BaseAdapter或ArrayAdapter。 - 自定义Adapter需要重写`getView()`方法,该方法负责为ListView的每个条目生成视图。在...
为了实现用户只能选择一个条目的功能,我们经常会在ListView的每一项中添加RadioButton。本文将详细讲解如何在ListView中实现RadioButton的单选操作,并提及与GridView的相似性。 首先,我们需要了解ListView的基本...
1、这个主要是针对于考试类程序用的,比如其中如何向ListView中动态添加多个RadioButton单选题选项以及多个CheckBox多选题选项,另外,多个填空题的话,也可以用类似的方法整。 2、解决ListView中添加Button、...
在这个方法中,为每一项ListView项添加RadioButton,并处理选中状态。 - 设置单选行为:由于ListView的复用机制,不能直接在RadioButton中使用RadioGroup,否则可能导致选中状态混乱。需要在Adapter中记录当前选中...
在处理用户交互时,我们有时需要在ListView的每一项中添加选择功能。在本案例中,我们需要将原本的多选框(CheckBox)替换为单选按钮(RadioButton),以实现列表中的单选效果。以下是对这个主题的详细讲解: 1. **...
这个项目专注于在ListView中添加多种类型的items,使得开发者可以构建出具有丰富交互性的应用,例如创建调查问卷或设计简单的考题。以下是对这个项目的详细解读: 首先,我们要了解ListView的工作原理。ListView...
- **保存选择状态**:在Adapter的列表数据模型中,为每个item添加一个标识来记录其RadioButton的状态。 - **在onBindViewHolder()中设置状态**:根据数据模型的标识,设置每个RadioButton的checked属性。 - **...
每个ListView的列表项对应一个RadioButton,RadioGroup则可以管理这些RadioButton,确保同一时间只有一个被选中。在ListView的适配器中,我们需要创建包含RadioButton的列表项布局,并在适配器的getView()方法中设置...
2.2 自定义ListView项布局:在XML布局文件中,为ListView的每一项添加CheckBox,并设置相应的ID。确保CheckBox与数据项绑定时,每个CheckBox都有唯一的标识。 2.3 设置选择状态:在getView()方法中,根据数据项的...
每个ListView项中包含一个RadioButton,RadioGroup可以设置为线性或网格布局,以决定RadioButton的排列方式。 - 在Adapter中,为每个ListView项的View设置一个RadioButton,并在getView()方法中处理选中状态。可以...
9. **动态添加RadioButton**:在代码中动态创建和添加RadioButton到RadioGroup,可以提供更大的灵活性,尤其是在选项数量不确定或需要动态加载的情况下。 10. **适配器和RecyclerView**:如果RadioButton是列表视图...
在这个布局文件中,添加一个RadioButton作为选中标志。 ```xml <RadioButton android:id="@+id/radioButton" android:layout_width="wrap_content" android:layout_height="wrap_content" android:checked=...
在某些场景下,我们可能需要在ListView的每一项中添加RadioButton,以便让用户进行单选操作。本篇文章将详细讲解如何在Android的ListView中结合RadioButton实现单选功能。 首先,我们需要了解RadioButton的基本用法...
4. **监听ListView的点击事件**:为了响应用户点击列表项,我们可以为ListView添加一个OnItemClickListener。这将使我们能够获取被选中的项,并执行相应的操作。 ```java listView.setOnItemClickListener(new ...
在getView()方法中,为每个ListView项设置一个RadioButton,并将其添加到一个RadioGroup中。 2. **设置OnCheckedChangeListener**:在Adapter中,为RadioGroup设置一个OnCheckedChangeListener,当RadioButton的...
在ListView中集成单选按钮(RadioButton)和多选按钮(CheckBox)是常见的需求,例如在创建选择列表、设置菜单等场景。本篇文章将深入探讨如何在ListView中实现单选与多选功能,并解决复用问题。 首先,我们需要...
在ListView的适配器中,每个列表项包含一个RadioButton,RadioGroup可以在整个ListView层级进行管理,确保一次只能选中一个项目。当RadioButton的状态改变时,可以通过监听CheckedChangeListener回调更新相应的数据...
在处理ListView中的单选冲突时,主要考虑的是防止同一时间有多个RadioButton被选中。通过在Adapter中维护选中位置,并在点击事件中更新状态,我们可以确保只有一个Item是选中的。同时,我们还需要注意在ListView的...
1. **创建RadioButton布局**:为ListView的每一项创建一个XML布局文件,其中包含一个RadioButton。例如,一个名为`list_item_single_choice.xml`的布局文件: ```xml android:layout_width="match_parent" ...