i want to show a listview with check box like
checkbox listitem1
checkbox listitem2
checkbox listitem3
.
.
.
.
If click on any listitem in listview then the corresponding check box checked will be true . I tried below code
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<CheckBox android:text=""
android:id="@+id/list_checkbox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="false"
></CheckBox>
<TextView
android:id="@+id/songname"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_marginTop="10px"
android:layout_marginLeft="60px"/>
<TextView
android:id="@+id/artist"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_marginTop="30px"
android:layout_marginLeft="60px"/>
</RelativeLayout>
The class file is
list.setOnItemClickListener(this);
list.setAdapter(new EfficientAdapter(this));
private static class EfficientAdapter extends BaseAdapter
{
private LayoutInflater mInflater;
public EfficientAdapter(Context context)
{
mInflater = LayoutInflater.from(context);
}
public int getCount()
{
return title.length;
}
public Object getItem(int position)
{
return position;
}
public long getItemId(int position)
{
return position;
}
public View getView(int position, View convertView, ViewGroup parent)
{
ViewHolder holder;
if (convertView == null)
{
convertView = mInflater.inflate(R.layout.selectsongs, null);
holder = new ViewHolder();
holder.title = (TextView) convertView.findViewById(R.id.songname);
holder.artist = (TextView) convertView.findViewById(R.id.artist);
holder.check = (CheckBox) convertView.findViewById(R.id.list_checkbox);
convertView.setTag(holder);
}
else
{
holder = (ViewHolder) convertView.getTag();
}
holder.title.setText(title[position]);
holder.artist.setText(artist[position]);
return convertView;
}
static class ViewHolder
{
TextView title,artist;
CheckBox check;
}
}
@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int position, long arg3) {
// TODO Auto-generated method stub
Log.e("name",title[position]);
}
but in this the OnClickItemClickListener on the listview is not working. The checkbox checkable is true when i click on the check box not on listitem in listview. So please tell me how to show the listview with checkbox and also listitem checkbox checkable is true when i click on the listitem.
Best Regards.
Thanks in advance