Skip to content Skip to sidebar Skip to footer

Enable Clicking On List Items Android

my code displays installed apps having specific permissions in a listview. i want to open the settings where you can uninstall apps on each list item (app) .How do i do that? here

Solution 1:

@OverrideprotectedvoidonCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
      getInstalledApps(this);
      ArrayAdapteradapter=newArrayAdapter<String>(this, R.layout.activity_listview, results);

      ListViewlistView= (ListView) findViewById(R.id.mobile_list);
      listView.setAdapter(adapter);
      listView.setOnItemClickListener(this);
   }


@OverridepublicvoidonItemClick(AdapterView<?> parent, View view, int position,
        long id) { 

    //your code here

}

Solution 2:

Try with this:

listView.setOnItemClickListener(newOnItemClickListener() {
            @OverridepublicvoidonItemClick(AdapterView<?> parent, View view, int position,
                    long id) {
                StringpackageName= (String)parent.getItemAtPosition(position);
            try {
                // Open the specific App Info page:Intentintent=newIntent(android.provider.Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
                intent.setData(Uri.parse("package:" + packageName));
                startActivity(intent);
            } catch (ActivityNotFoundException e) {
                // e.printStackTrace();// Open the generic Apps page:Intentintent=newIntent(  android.provider.Settings.ACTION_MANAGE_APPLICATIONS_SETTINGS);
                startActivity(intent);
            }
        });

See if it works..

Solution 3:

Paste this code inside your onCreate() below listView.setAdapter(adapter);

 listView.setOnItemClickListener(newOnItemClickListener() {
        @OverridepublicvoidonItemClick(AdapterView<?> parent, View view, int position,
                long id) {
            StringpackageName= results.get(position);
            Intentintent=newIntent(android.provider.Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
            intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            intent.setData(Uri.parse("package:" + packageName));
            startActivity(intent);
        }
    });

Post a Comment for "Enable Clicking On List Items Android"