사용자와 아이콘이 설치 한 응용 프로그램을 나열하려고합니다. 지금까지 나는 사용자가 설치된 응용 프로그램을 얻을 수 있었지만 응용 프로그램 이름과 아이콘이 함께 목록에 표시하는 데 문제가 있습니다.응용 프로그램 앞에있는 아이콘을 목록에 추가하는 방법
목록 :: {아이콘} test_application활동의
예 : 행
ArrayList<String> listing = null;
listing = new ArrayList<String>();
ArrayList<Object> icons = new ArrayList<Object>();
CharSequence c = null;
int count = 0;
Drawable icon = null;
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
TextView i = (TextView) findViewById(R.id.textView1);
PackageManager pm = getPackageManager();
List<ApplicationInfo> packages = pm
.getInstalledApplications(PackageManager.GET_META_DATA);
for (ApplicationInfo applicationInfo : packages) {
if ((applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 1) {
count = count + 1;
try {
c = pm.getApplicationLabel(pm.getApplicationInfo(
applicationInfo.processName,
PackageManager.GET_META_DATA));
icon = pm.getApplicationIcon(applicationInfo.packageName);
} catch (NameNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
listing.add(c.toString());
,icons.add(icon)
}
}
ListView list = (ListView) findViewById(R.id.listView1);
list.setAdapter(new ArrayAdapter<String>(this, R.layout.text, R.id.textView1, listing));
String Counting = String.valueOf(count);
i.setText(Counting);
}
}
XML
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
tools:context=".MainActivity" />
<ListView
android:id="@+id/listView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true" >
</ListView>
</RelativeLayout>
행 XML
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<ImageView
android:id="@+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
/>
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_toRightOf="@+id/imageView1"
/>
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/imageView1"
android:layout_toRightOf="@+id/textView1"
android:text="TextView" />
</RelativeLayout>
을 "하지만 난 문제 목록에서 퍼팅을 데"정확히 무슨 문제있어? – Simon
무엇이 문제입니까? 당신은 목록보기를 얻지 못하고 있습니까? –
아이콘에는 하나의 변수 만 있습니다. 어떻게 그것을 목록에서 사용할 계획입니까? 귀하의 코드는 아이콘이 아닌 응용 프로그램의 이름 만 표시합니다 ... –