gpt4 book ai didi

java - OnLongClick 停止 OnClick

转载 作者:搜寻专家 更新时间:2023-11-01 08:04:50 27 4
gpt4 key购买 nike

我正在使用 ListView 。在实现 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;
}
}

最佳答案

我认为您不应该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;
}
});

我从 how to capture long press event for Listeview item of a ListActivity? 中获取了代码

希望这对您有所帮助。

关于java - OnLongClick 停止 OnClick,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15774408/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com