I have a custom adapter for a list view. The row view is a check box. I have used setOnClickListener() to handle when the user clicks the check box. What I am wondering is if there is a way for me to know the position of the check box in the list view when it is clicked.
Here is the code for my adapter if it helps.
private class TagAdapter extends BaseAdapter
{
public TagAdapter(ArrayList<Tag> items)
{
mTagList = items;
}
public int getCount()
{
return mTagList.size();
}
public Object getItem(int position)
{
return mTagList.get(position);
}
public long getItemId(int position)
{
return position;
}
public View getView(int position, View convertView, ViewGroup parent)
{
View V = convertView;
if(V == null)
{
LayoutInflater vi = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
V = vi.inflate(R.layout.tag, null);
}
Tag t = (Tag) mTagList.get(position);
TextView tagName = (TextView)V.findViewById(R.id.checkBox1);
CheckBox cb = (CheckBox)V.findViewById(R.id.checkBox1);
cb.setChecked(t.isSelected());
cb.setOnClickListener(new View.OnClickListener() //the add tag button "+"
{
public void onClick(View view)
{
}
});
tagName.setText(t.getTagName());
return V;
}
}
When you create the check box use the
setTagmethod to add any data you want. You can even store the list item as the tag.