0
檢查我有了3個textboxs,圖像,並在GridView一個複選框ViewHolder。問題是,我似乎無法捕捉/觸發onclicklistener後,我加入的複選框,此viewholder。 只有複選框似乎設置爲選中或未選中。如果我點擊是在圖像或文本框我想觸發onClick事件的其他區域。ViewHolder對於一個GridView - 複選框與onclicklistener不工作
另外,如果有人有線索,如果我們能setclickable假幾個複選框,因此它可以被看作但不積極迴應。
我此刻的代碼是在ImageAdpater:
在離imageadpater被稱爲活動public View getView(int position, View convertView, ViewGroup parent)
{
ViewHolder holder;
ImageView imgView = null;
if (convertView == null) {
holder = new ViewHolder();
LayoutInflater ltInflate = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = ltInflate.inflate(R.layout.griditem, null);
holder.textview1 = (TextView) convertView.findViewById(R.id.grid_item_alert_date);
holder.textview2 = (TextView) convertView.findViewById(R.id.grid_item_alert_time);
holder.textview3 = (TextView) convertView.findViewById(R.id.grid_item_alert_type);
holder.imageview = (ImageView) convertView.findViewById(R.id.grid_item_image);
holder.checkbox = (CheckBox) convertView.findViewById(R.id.checkbox_ack);
convertView.setTag(holder);
}
else
{
holder = (ViewHolder) convertView.getTag();
}
holder.checkbox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
// TODO Auto-generated method stub
Toast.makeText(context, " checkbox checked", Toast.LENGTH_SHORT).show();
} });
holder.textview1.setText("Text 1 ");
holder.textview2.setText("Text 2 ");
holder.textview3.setText("Text 3 ");
holder.checkbox.setChecked(false);
holder.imageview.setImageBitmap(bitmap);
holder.id = position;
return convertView;
}
代碼:
GridView gridview = (GridView) findViewById(R.id.mygridview);
adapter = new ImageAdapter(this);
gridview.setAdapter(adapter);
gridview.setOnItemClickListener(new OnItemClickListener()
{
public void onItemClick(AdapterView<?> parent, View v, int position, long id)
{
Toast.makeText(getBaseContext(),"pic" + (position + 1) + " selected",
Toast.LENGTH_SHORT).show();
}
}
);
所以gridview.setOnItemClickListener在上面不會被調用,爲什麼? 我曾嘗試不同的設置,但似乎沒有任何工作,只複選框事件的作品和太如果getView如上定義。
在需要迫切解決的,乾杯