Listvew With Textview And Checkbox
I want to have a listview with textview + check box. I was able to create the listview. I can capture listview item select. However when I try to capture check box select, unselect
Solution 1:
You can maintain seperate adpater class so that you can achive this easily....
publicclassbsAdapterextendsBaseAdapter
{
Activity cntx;
publicbsAdapter(Activity context)
{
// TODO Auto-generated constructor stubthis.cntx=context;
}
publicintgetCount()
{
// TODO Auto-generated method stubreturn listview_arr.length;
}
public Object getItem(int position)
{
// TODO Auto-generated method stubreturn listview_arr[position];
}
publiclonggetItemId(int position)
{
// TODO Auto-generated method stubreturn listview_array.length;
}
public View getView(finalint position, View convertView, ViewGroup parent)
{
View row=null;
LayoutInflater inflater=cntx.getLayoutInflater();
row=inflater.inflate(R.layout.search_list_item, null);
TextView tv=(TextView)row.findViewById(R.id.title);
CheckBox cb=(CheckBox)row.findViewById(R.id.cb01);
tv.setText(listview_arr[position]);
cb.setOnClickListener(newOnClickListener(){
publicvoidonClick(View v) {
if(cb.ischecked)
{
//ur code
}
else//ur code
}
});
return row;
}
}
Post a Comment for "Listvew With Textview And Checkbox"