我有类包含onListItemClick
和onItemLongClick
和列表视图的适配器类。我的问题是onItemLongClick
从来没有叫我如何解决这个问题?
public class FilePicker extends ListActivity implements AdapterView.OnItemLongClickListener {
...
@Override
protected void onListItemClick(ListView l, View v,int position, long id) {
Toast.makeText(getApplicationContext(),"SHORT",Toast.LENGTH_LONG).show();
super.onListItemClick(l, v, position, id);
}
@Override
public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
Toast.makeText(getApplicationContext(),"LOOOONG",Toast.LENGTH_LONG).show();
return true;
}
private class FilePickerListAdapter extends ArrayAdapter<File> {
private List<File> obj;
public FilePickerListAdapter(Context context, List<File> objects) {
super(context, R.layout.list_item_browse, android.R.id.text1, objects);
obj = objects;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View r = null;
if(convertView == null) {
LayoutInflater inflater = (LayoutInflater)
getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
r = inflater.inflate(R.layout.list_item_browse, parent, false);
}
else
r = convertView;
File object = obj.get(position);
ImageView imageView = (ImageView)r.findViewById(R.id.file_picker_image);
TextView textView = (TextView)r.findViewById(R.id.file_picker_text);
textView.setSingleLine(true);
textView.setText(object.getName());
if(object.isFile())
imageView.setImageResource(R.drawable.play);
else
imageView.setImageResource(R.drawable.folder);
return r;
}
}
}
我也试过了android:longClickable="true"
,RelativeLayout(list_item_browse)
但是不行。
您忘记为 RelativeLayout 注册点击侦听器。
yourRelativeLayout.setOnLongClickListener(this);
初始化布局后在 getView 中添加。
编辑:如果您想要为 listview 使用 longclickListener 则在您的活动中使用 listview 注册监听器并在您的活动中实现该方法
yourListView.setOnItemLongClickListener(this);
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句