我正在处理自定义列表视图
这是我的适配器类
public class MenubaseAdapter extends BaseAdapter {
private static ArrayList<MenuItem> searchMenuItemArraylist;
private LayoutInflater menuInflater;
public MenubaseAdapter( Context context,ArrayList<MenuItem> results) {
searchMenuItemArraylist=results;
menuInflater = LayoutInflater.from(context);
}
@Override
public int getCount() {
// TODO Auto-generated method stub
return searchMenuItemArraylist.size();
}
@Override
public Object getItem(int position) {
// TODO Auto-generated method stub
return position;
}
@Override
public long getItemId(int position) {
// TODO Auto-generated method stub
return position;
}
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
iewHolder holder;
if(convertView==null)
{
convertView=menuInflater.inflate(R.layout.menu_list, null);
holder=new MenuViewHolder();
holder.txtItemName=(TextView)convertView.findViewById(R.id.textView_menuitem);
holder.txtItemPrice=(TextView)convertView.findViewById(R.id.textView_itemprice);
holder.txtItemQty=(TextView)convertView.findViewById(R.id.TextView_itemQty);
holder.selectChk=(CheckBox)convertView.findViewById(R.id.checkBox_menuchk);
convertView.setTag(holder);
}else {
holder=(MenuViewHolder)convertView.getTag();
}
holder.txtItemName.setText(searchMenuItemArraylist.get(position).getMenuItemname());
holder.txtItemPrice.setText(searchMenuItemArraylist.get(position).getMenuItemPrice());
holder.txtItemQty.setText(searchMenuItemArraylist.get(position).getItemQty());
holder.selectChk.setChecked(searchMenuItemArraylist.get(position).isSelected());
holder.selectChk.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
//how to select the listview item ?
}
});
return convertView;
}
static class MenuViewHolder
{
TextView txtItemName;
TextView txtItemPrice;
TextView txtItemQty;
CheckBox selectChk;
}
}
现在我的问题是,当我单击 foodmenuitems 时,列表被选中并且复选框被选中。但是如果我只单击复选框,那么列表项将不会被提前选中。thnx。