如何從每個列表視圖項目的左側添加可繪製文件夾中的縮略圖圖像?在列表視圖項目旁邊添加縮略圖
我也想算的列表項目的數目,在我的TextView顯示它們
任何幫助,將不勝感激! IM停留在這個很長一段時間
public class MainActivity extends Activity {
ArrayList<String> results = new ArrayList<String>();
ArrayList<String> packageNames = new ArrayList<String>();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
getInstalledApps(this);
ArrayAdapter adapter = new ArrayAdapter<String>(this,
R.layout.activity_listview, results);
ListView listView = (ListView) findViewById(R.id.mobile_list);
listView.setAdapter(adapter);
listView.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
String packageName = packageNames.get(position);
Intent intent = new Intent(
android.provider.Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.setData(Uri.parse("package:" + packageName));
startActivity(intent);
}
});
}
private ArrayList<String> getInstalledApps(Context context) {
PackageManager packageManager = context.getPackageManager();
List<PackageInfo> applist = packageManager.getInstalledPackages(0);
Iterator<PackageInfo> it = applist.iterator();
while (it.hasNext()) {
PackageInfo pk = (PackageInfo) it.next();
if ((pk.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0) {
Log.v("system app using internet = ",
"" + pk.applicationInfo.loadLabel(packageManager));
continue;
}
if (PackageManager.PERMISSION_GRANTED == packageManager
.checkPermission(Manifest.permission.INTERNET,
pk.packageName)
|| PackageManager.PERMISSION_GRANTED == packageManager
.checkPermission(
Manifest.permission.READ_EXTERNAL_STORAGE,
pk.packageName)) {
results.add("" + pk.applicationInfo.loadLabel(packageManager));
packageNames.add(pk.packageName);
}
}
Log.v("app using internet = ", results.toString());
return results;
}
}
更改適配器的'getView'方法。 – Rohit5k2
嗨,你可以參考這個鏈接。 http://www.vogella.com/tutorials/AndroidListView/article.html – Nik