-1
我有一個自定義的適配器類,它擴展了基礎適配器。我試圖在視圖項目上實現onTouchListener。但它不起作用。請幫忙。onTouchListener不能使用自定義視圖
這裏是代碼段
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
View cellView=convertView;
ViewHolder viewHolder;
if(cellView==null) {
LayoutInflater layoutInflater = (LayoutInflater) context.
getSystemService(Context.LAYOUT_INFLATER_SERVICE);
cellView = layoutInflater.inflate(R.layout.grid_topics, parent, false);
viewHolder = new ViewHolder();
viewHolder.icon = (ImageView) cellView.findViewById(R.id.cellImageView);
viewHolder.text = (TextView) cellView.findViewById(R.id.cellTextView);
cellView.setTag(viewHolder);
} else {
viewHolder = (ViewHolder) cellView.getTag();
}
viewHolder.icon.setImageBitmap(list.get(position).image);
viewHolder.text.setText(list.get(position).text);
cellView.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_UP) {
Toast.makeText(context, list.get(position).text, Toast.LENGTH_SHORT).show();
return true;
}
return false;
}
});
return cellView;
}
不,它仍然沒有工作。你的代碼與我的代碼有什麼不同? –