2

我正在使用列表视图。在实施 OnLongClick 之前,我的 onListItemClick 工作得很好,但是现在,在实施 OnLongClick 之后,长点击工作和正常的列表点击什么都不做。它似乎隐藏了您已经使用的 onListItemClick() 函数

谁能看到为什么/提出解决方案?

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> implements OnLongClickListener{
 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]);
  rowView.setOnLongClickListener(new OnLongClickListener(){

            public boolean onLongClick(View arg0) {
             context.startActivity(new Intent(context,RestoreOriginal.class));
                return false;
            }
        });
 // Change icon based on name
  String s = values[position];

  if (s.equals("a")) {
   imageView.setImageResource(R.drawable.a);

return rowView;
}
}
4

1 回答 1

4

我认为你不应该这样做rowView.setOnLongClickListener

尝试这样的事情:

this.getListView().setLongClickable(true);
this.getListView().setOnItemLongClickListener(new OnItemLongClickListener() {
    public boolean onItemLongClick(AdapterView<?> parent, View v, int position, long id) {
// whatever you wanna do
        return true;
    }
});

我从如何捕获 ListActivity 的 Listeview 项的长按事件中获取代码?

希望这可以帮助。

于 2013-04-03T00:24:02.733 回答