在每行中单击ListView
包含ToggleButton
、Button
和的自定义项时遇到问题。问题:当我单独单击每个视图时,如何为每个视图调用不同的操作?我的代码:TextView
Spinner
public class CustomListAdapter extends BaseAdapter {
Context _context;
private ArrayList<String> _list;
public CustomListAdapter(Context context,
ArrayList<String> listItems) {
_context= context;
_list = listItems;
}
public int getCount(){
return _list.size();
}
public long getItemId(int position){
return position;
}
public Object getItem(int position){
return _list.get(position);
}
public View getView(int position,View convertView,ViewGroup parent)
{
ViewContainer container = new ViewContainer();
if(convertView == null)
{
LayoutInflater inflater = LayoutInflater.from(_context);
convertView = inflater.inflate(R.layout.elements,parent, false);
convertView.setTag(container);
convertView.setClickable(true);
container.listIcon = (ToggleButton)convertView.findViewById(R.id.togle_item);
container.listText = (TextView)convertView.findViewById(R.id.text_listitem);
container.spinner=(Spinner)convertView.findViewById(R.id.spinner1);
container.but=(Button)convertView.findViewById(R.id.button1);
convertView.setOnClickListener(new OnClickListener() {
public void onItemClick(AdapterView<?> arg0, View arg1, int position, long arg3)
{
**How can I do that when I click each view individually, different action is called for each view???**
}
public void onClick(View v) {
}
}
);
}
container = (ViewContainer) convertView.getTag();
ToggleButton myListIcon = container.listIcon;
myListIcon.setChecked(true);
Button MyButton=container.but;
TextView myListText = container.listText;
myListText.setText(_list.get(position));
Spinner MySpinner=container.spinner;
MySpinner.setAdapter(adapter);
container = null;
return convertView;
}
private class ViewContainer
{
private ToggleButton listIcon;
private TextView listText;
private Spinner spinner;
private Button but;
}
}