我努力尝试实现一个OnLongClick功能 - 我不明白在哪里添加一个侦听器并定义结果方法。在哪里初始化onLongClickListener
我使用的实现使用了一个适配器 - 并没有onClickListener,但工作正常。任何人都可以提出哪里/如何实现OnLongClick听众
我不需要每个项目在列表中执行不同的操作 - 在屏幕上只是anywere拿起长按
public class CombChange extends ListActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setListAdapter(new ListEdit(this, symbols));
@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
String selectedValue = (String) getListAdapter().getItem(position);
if (lastPressed.equals(selectedValue)){
count++;}
}
public class ListEdit extends ArrayAdapter<String> {
private final Context context;
private final String[] values;
public ListEdit(Context context, String[] values) {
super(context, R.layout.activity_comb_change, values);
this.context = context;
this.values = values;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater inflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View rowView = inflater.inflate(R.layout.activity_comb_change, parent, false);
TextView textView = (TextView) rowView.findViewById(R.id.label);
ImageView imageView = (ImageView) rowView.findViewById(R.id.logo);
textView.setText(values[position]);
// Change icon based on name
String s = values[position];
if (s.equals("a")) {
imageView.setImageResource(R.drawable.a);
return rowView;
}
}
实现OngestureListener正如我刚才3分钟前[这里] [1] 那里有一个Onlongpressed()方法贴出来,那是什么u需要 [1]:HTTP:// stackoverflow.com/questions/15770887/how-to-handle-swipe-down-gesture-on-an-imageview/15771081#15771081 –