How to check the CheckBox of ListView when item clicked?
I have a ListView with CheckBox, TextView, Button.
Here i want to select multiple rows of ListView and so used CheckBox. If i click on a row, i want to make its corresponding CheckBox to be checked and get the RowID of the clicked item of ListView.
If i click on Button, i want to open a pop-up or another Screen(Activity) but CheckBox must not be checked.
How to do this? Please help.
Thanks in advance.
Edit:
This is how my layout looks.
Code is simple using Adapter to the ListView.
public class Adapter extends BaseAdapter{
private Context context;
Button btnView;
CheckBox box;
ArrayList<String> altextView1;
ArrayList<String> altextView2;
public Adapter(Context c, Button view, CheckBox checkBox, ArrayList<String> textView1, ArrayList<String> textView2) {
this.context=c;
this.btnView=view;
this.box=checkBox;
this.altextView1=textView1;
this.altextView2=textView2;
}
@Override
public int getCount() {
// TODO Auto-generated method stub
return altextView1.size();
}
@Override
public Object getItem(int arg0) {
// TODO Auto-generated method stub
return null;
}
@Override
public long getItemId(int arg0) {
// TODO Auto-generated method stub
return 0;
}
@Override
public View getView(int arg0, View arg1, ViewGroup arg2) {
// TODO Auto-generated method stub
View view=arg1;
view=LayoutInflater.from(context).inflate(R.layout.list7, null);
TextView tv1=(TextView)view.findViewById(R.id.tV1);
TextView tv2=(TextView)view.findViewById(R.id.tV2);
btnView=(Button)findViewById(R.id.btnView);
box=(CheckBox)findViewById(R.id.cB);
tv1.setText(altextView1.get(arg0));
tv2.setText(altextView2.get(arg0));
return view;
}
}