我努力嘗試實現一個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 –