There was a question concerning removal of appendices in the program. I use such code:
import java.util.ArrayList;
import java.util.List;
import android.app.Activity;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
public class dop extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.dop);
PackageManager pm = this.getPackageManager();
Intent intent = new Intent(Intent.ACTION_MAIN, null);
intent.addCategory(Intent.CATEGORY_LAUNCHER);
List<String> myList = new ArrayList<String>();
ArrayList<ResolveInfo> list = (ArrayList<ResolveInfo>) pm.queryIntentActivities(intent, PackageManager.PERMISSION_GRANTED);
for (ResolveInfo rInfo : list) {
System.out.println("Installed Applications " + rInfo.activityInfo.applicationInfo.loadLabel(pm).toString());
myList.add(rInfo.activityInfo.applicationInfo.loadLabel(pm).toString());
}
ListView listView = (ListView) findViewById(R.id.list);
ArrayAdapter<String> aa = new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1, myList);
listView.setAdapter(aa);
}
public void onListItemClick(
ListView parent, View v, int position, long id) {
Intent intent = new Intent(Intent.ACTION_DELETE);
intent.setData(Uri.parse("package:"+"some.package.to.remove"));
startActivity(intent);
}
}
But the removal code doesn’t work. What I not so do?
onListItemClick()is available only inListActivity(and it’s actually a protected member), so basically you’re not overriding anything and that method is never getting called.(to be sure you’re overriding something, put
@Overridebefore that method, the compiler will complain if that’s not an override and you’ll know something is wrong there)As you’re building an
Activity, you’ll need to make it implementOnItemClickListener, and inonCreate()set this listener on theListView: