Note that there are some explanatory texts on larger screens.

plurals
  1. POListView adding items
    text
    copied!<p>Okay, first off, i started (trying) to learn Java about 2 days ago. im trying to make an application that lists all installed applications (activityInfo.loadLabel) and i want to launch the application on item click (activityInfo.packageName) i have these stored in a list of AppItems</p> <pre><code>class AppItem{ String _appname; public String getAppname(){return _appname;}; public void setAppname(String value){_appname = value;}; String _app; public String getApp(){ return _app; }; public void setApp(String value){_app = value; }; } </code></pre> <p>I can add an array of strings to my listview just fine. but how do i add 2 different values to the same row (so to speak) in a listview - in Java. please tell me if you dont understand my question - and il'l try to elaborate best possible</p> <p>here is my code:</p> <pre><code>ArrayList&lt;AppItem&gt; apps; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); final Intent mainIntent = new Intent(Intent.ACTION_MAIN, null); mainIntent.addCategory(Intent.CATEGORY_LAUNCHER); final List&lt;ResolveInfo&gt; pkgAppsList = getPackageManager().queryIntentActivities(mainIntent, 0); AppItem appItem = new AppItem(); for (ResolveInfo applicationInfo : pkgAppsList) { appItem._appname = (String) applicationInfo.activityInfo.loadLabel(getPackageManager()); appItem._app= applicationInfo.activityInfo.packageName; apps.add(appItem); } ArrayAdapter&lt;AppItem&gt; adapter = new ArrayAdapter&lt;AppItem&gt;(this,android.R.layout.simple_list_item_1,apps); ListView listView = new ListView(this); listView.setAdapter(adapter); setContentView(listView); listView.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView&lt;?&gt; parent, View view, int position, long id) { String item = ((TextView)view).getText().toString(); Toast.makeText(getBaseContext(), item, Toast.LENGTH_LONG).show(); } }); } class AppItem{ String _appname; public String getAppname(){return _appname;}; public void setAppname(String value){_appname = value;}; String _app; public String getApp(){ return _app; }; public void setApp(String value){_app = value; }; } </code></pre> <p>or is there an alternative to using</p> <pre><code>Intent LaunchIntent = getPackageManager().getLaunchIntentForPackage("com.package.address"); startActivity(LaunchIntent); </code></pre> <p>would i be able to start an application via its label name?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload