好吧,首先,我開始(嘗試)在2天前學習Java。 我嘗試做,列出了所有安裝的應用程序(activityInfo.loadLabel) 的應用程序,我想推出的項目點擊(activityInfo.packageName) 我有這些存儲在AppItems列表應用ListView添加項目
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; };
}
我可以添加一個字符串數組到我的列表視圖就好了。 但我如何添加2個不同的值到同一行(可以這麼說)在列表視圖 - 在Java中。 請告訴我,如果你不明白我的問題 - 和il'l嘗試制定最佳的
這裏是我的代碼:
ArrayList<AppItem> 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<ResolveInfo> 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<AppItem> adapter = new ArrayAdapter<AppItem>(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<?> 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; };
}
或 有使用
Intent LaunchIntent = getPackageManager().getLaunchIntentForPackage("com.package.address");
startActivity(LaunchIntent);
替代
我可以通過其標籤名稱啓動應用程序嗎?
我不明白爲什麼你需要在同一行 – njzk2
在2項以及我所需要的文本作爲標籤 - 我需要調用的包名,所以我可以得到應用程序啓動 - 除非有辦法通過標籤啓動應用程序?在c#我會使用文本字段和描述字段或類似的東西,所以我可以得到所選項目的描述 – VisualBean
請點擊鏈接[按照鏈接](http://impressive-artworx.de/2011/list -all-installed-apps-in-style /) – skygeek