在我的應用程序中,我必須在列表視圖中列出已安裝的應用程序。應用程序在後臺線程中獲取已安裝的應用程序。要求是要填充列表事件,但是沒有完成提取操作,即如果在數組列表中有一個條目,則使用該條目顯示數組列表。這是可能的嗎?請幫助我。提前感謝使用當前存在的元素填充android列表
2
A
回答
2
首先,只有當您使用循環來處理背景中的應用程序數據時纔有可能。概要:
類舉行應用信息:
Class AppData {
public final Drawable icon;
public final String name;
public AppData(Drawable i, String n){
this.icon = i;
this.name = n;
}
}
AsynckTask搜索應用程序:
AsyncTask<Void,AppData,Void> scanAppsTask = new AsyncTask<Void,AppData,Void>{
@Override
public Void doInBackground(Void... args){
//--get list---
List<ApplicationInfo> apps = mPm.getInstalledApplications(
PackageManager.GET_UNINSTALLED_PACKAGES |
PackageManager.GET_DISABLED_COMPONENTS);
//--run a loop--
for(ApplicationInfo appInfo : apps){
AppData newFound;
//---find app details, load app icon etc---
publishProgress(newFound);
}
//---done---
return null;
}
@Override
public void onProgressUpdate(AppData... data){
//---update list for every app found----
myListAdapter.add(data[0]);
myListAdapter.notifyDataSetChanged();
}
}
scanAppsTask.execute();
1
我正在研究一個類似的應用程序,我需要獲取所有已安裝的應用程序,甚至內置的應用程序。我用下面的代碼做了這個,
TextView data;
ImageView image1;
LinearLayout holdlayout;
View l1;
private ArrayList results = new ArrayList();
List<ResolveInfo> list;
TextView result;
String str="";
Drawable icon;
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
l1 = findViewById(R.id.Layout1);
PackageManager pm = this.getPackageManager();
Intent intent = new Intent(Intent.ACTION_MAIN, null);
intent.addCategory(Intent.CATEGORY_LAUNCHER);
list = pm.queryIntentActivities(intent, PackageManager.PERMISSION_GRANTED);
for (ResolveInfo rInfo : list)
{
str = rInfo.activityInfo.applicationInfo.loadLabel(pm).toString() + "\n";
results.add(rInfo.activityInfo.applicationInfo.loadLabel(pm).toString());
Log.w("Installed Applications", rInfo.activityInfo.applicationInfo.loadLabel(pm).toString());
icon = rInfo.activityInfo.applicationInfo.loadIcon(pm);
holdlayout = new LinearLayout(getApplicationContext());
holdlayout.setOrientation(LinearLayout.HORIZONTAL);
data = new TextView(getApplicationContext());
data.setText(str);
image1 = new ImageView(getApplicationContext());
image1.setBackgroundDrawable(icon);
((ViewGroup) holdlayout).addView(image1);
((ViewGroup) holdlayout).addView(data);
((ViewGroup) l1).addView(holdlayout);
}
}
讓我知道,如果您在此代碼中有任何問題。
+0
我有一個doubt.My後臺線程通過one.Then返回整個列表,而不是一個我如何填充列表 – user1767260
+0
您可以創建一個自定義列表適配器來填充lkist。 –
1
您可以從ListView
的適配器中添加/刪除項目,所以是的,您可以在新項目可用時儘快從後臺線程填充項目列表。
相關問題
- 1. PHP表元素不填充在適當
- 2. 使用Python中不同列表中的元素填充列表
- 3. 當列表填充屏幕時,android元素下面的列表不見了
- 4. 在列表元素中填充空格
- 5. 使用顯示錶在jsp上填充列表元素
- 6. 填充父列表元素的值
- 7. 複製下拉列表元素來填充NA列表元素
- 8. 使用許多元素填充表格
- 9. 如何使用查詢中不存在的值列表填充選擇元素
- 10. 如何加載這些元素來在android中填充列表?
- 11. 使用Python中以前未知數量的元素填充一個空列表
- 12. 向表中添加新列時,使用默認單元格填充當前行
- 13. 用對象填充數組列表使所有元素在列表中相同
- 14. Android - 使用AsycTaskLoader&MySql填充列表
- 15. 如何在page_load()之前使用javascript填充html元素?
- 16. 如何使元素填充表格行
- 17. 如何在僞元素之前忽略元素填充?
- 18. 動態填充CSS使用Angular2動態填充css僞元素'之前'內容
- 19. MATLAB使用單元陣列中的元素填充矩陣
- 20. 使用當前時間填充div
- 21. bootstrap,在元素中填充
- 22. 在表中放置元素時無法填充下拉列表
- 23. 使用DataRow元素在MVC 4中填充SELECT元素
- 24. 在Firefox中使用textarea的列表元素頂部的邊/填充
- 25. 使用列表填充DropDownList
- 26. 使用列表填充ObjectListView
- 27. 使用列表填充jTable
- 28. 使用列表填充JTable
- 29. 只填充一個列表,只發生多個列表元素
- 30. 使用動態html填充元素
謝謝你。這個解決方案幫了我。 – user1767260