gpt4 book ai didi

java - Listview 和 onItemLongClick 不起作用

转载 作者:行者123 更新时间:2023-12-01 13:56:05 24 4
gpt4 key购买 nike

我有一个包含所有已安装应用程序的 ListView 。我需要 onItemLongClick 卸载我在 ListView 中单击的应用程序。 onItemLongClick 的起始代码是这样的:

@Override
public boolean onItemLongClick(AdapterView<?> arg0, View arg1, int arg2,
long arg3) {
// TODO Auto-generated method stub
return false;
}

这是用于卸载的:

ApplicationInfo app = applist.get(position);

Uri packageUri = Uri.parse("package:"+app.packageName);
Intent uninstallIntent =
new Intent(Intent.ACTION_DELETE, packageUri);
startActivity(uninstallIntent);

return true;

我还需要插入一些参数,我尝试了这个,但在 onItemLongClick 中出现错误:

protected boolean setOnItemLongClickListener(ListView l, View v, int position, long id) {
super.onItemLongClick(l, v, position, id);// Error

ApplicationInfo app = applist.get(position);

Uri packageUri = Uri.parse("package:"+app.packageName);
Intent uninstallIntent =
new Intent(Intent.ACTION_DELETE, packageUri);
startActivity(uninstallIntent);

return true;
}

如何解决?

最佳答案

尝试实现这个

import android.widget.AdapterView.OnItemLongClickListener;


yourListView.setOnItemLongClickListener(new OnItemLongClickListener() {

@Override
public boolean onItemLongClick(AdapterView<?> arg0, View arg1,
int arg2, long arg3) {
// TODO Auto-generated method stub
Toast.makeText(MainActivity.this, "delete item in position : " + arg2, Toast.LENGTH_SHORT).show();
return false;
}
});

关于java - Listview 和 onItemLongClick 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19618446/

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