我已经安装了所有应用程序的列表视图..我需要onItemLongClick
卸载我在列表视图中单击的应用程序。 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;
}
我该如何解决?
答案 0 :(得分:1)
尝试实现此
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;
}
});