我有一個Person類的ArrayList,其中包含該人的年齡和姓名。在適配器(擴展BaseAdapter)中,我有兩個TextViews(用於設置年齡和名稱的值)和一個複選框。這是需要膨脹到警報對話框。如何從多選項listview中獲取值alertdialog
如何使用警報對話框的multichoice來實現此功能。
而且我也看一些例子,但不瞭解有關布爾[]值的警告對話框中的屬性,這是我到目前爲止的代碼,但它仍然需要執行該multichoice模式..
<ListView
android:id="@+id/listView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clickable="true"
android:choiceMode="multipleChoice">
</ListView>
我alertdialog ..
AlertDialog.Builder ab=new AlertDialog.Builder(CustomListActivity.this);
LayoutInflater linf=(LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE);
View v1=linf.inflate(R.layout.dialog_list, null);
ab.setView(v1);
//ab.setTitle("Select a group");
lv=(ListView) v1.findViewById(R.id.listView1);
ma=new MyAdapter(CustomListActivity.this, plist);
lv.setAdapter(ma);
而且MYAdapter ..
public class MyAdapter extends BaseAdapter
{
Context ctx;
ArrayList<Person> plist;
LayoutInflater linf;
public PersonHolder ph=null;
public MyAdapter(Context ctx, ArrayList<Person> plist) {
super();
this.ctx = ctx;
this.plist = plist;
}
public class PersonHolder
{
public TextView age;
public TextView name;
public CheckBox check;
}
@Override
public int getCount() {
// TODO Auto-generated method stub
return plist.size();
}
@Override
public Object getItem(int position) {
// TODO Auto-generated method stub
return plist.get(position);
}
@Override
public long getItemId(int position) {
// TODO Auto-generated method stub
return 0;
}
@Override
public View getView(int position, View convertView, ViewGroup arg2) {
// TODO Auto-generated method stub
linf=(LayoutInflater) ctx.getSystemService(ctx.LAYOUT_INFLATER_SERVICE);
if(convertView==null)
{
convertView=linf.inflate(R.layout.row_item, null);
ph=new PersonHolder();
ph.age=(TextView) convertView.findViewById(R.id.text1);
ph.name=(TextView) convertView.findViewById(R.id.text2);
ph.check=(CheckBox) convertView.findViewById(R.id.checkBox1);
convertView.setTag(ph);
}
else
{
ph=(PersonHolder) convertView.getTag();
}
Person p=(Person) getItem(position);
ph.age.setText(p.getAge());
ph.name.setText(p.getName());
ph.check.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton arg0, boolean arg1) {
// TODO Auto-generated method stub
// if(ph.check.isChecked())
// {
ph.check.setSelected(arg1);
// }
// else
// {
// ph.check.setSelected(false);
// }
}
});
return convertView;
}
}
當複選框和列表視圖是顯示activity..Here我的情況是,我的列表視圖是在activity..while複選框處於adapter..but的對話框中,該解決方案可以應用無論如何通過你和Vipul的解決方案,我確實得到和想法..並實施它..感謝很多.. – AndroidMech