0

アプリケーションのラベルを ListView に入れました。OnItemClickListener からpackageName (com.blabla.blabla)を取得したい。どうすればいいですか?ここに私のコード:

uygList = new ArrayList<String>();

final PackageManager pm = getPackageManager();
List<ApplicationInfo> paketler = pm.getInstalledApplications(PackageManager.GET_META_DATA);
for (ApplicationInfo paketBilgi : paketler) {

    if (paketBilgi.packageName.equals(c.getString(0))) {

        uygList.add(paketBilgi.loadLabel(pm).toString());

        if (sayi<c.getCount()-1) {
            sayi++;
            c.moveToNext();
        }

    }

}

lv.setAdapter(new ArrayAdapter<String>(Uygulamalar.this, android.R.layout.simple_list_item_1, uygList));

lv.setOnItemClickListener(new OnItemClickListener() {
    @Override
    public void onItemClick(AdapterView<?> parent, View view, int pos, long id) {

        // I want to get the packageName that selected from ListView like (com.blabla.blabla)

    }
});
4

2 に答える 2

2

これを使用できます:

lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int pos, long id) {
            for (ApplicationInfo paketBilgi : paketler) {
                String s = paketBilgi.loadLabel(pm).toString();
                if(s.equals(uygList.get(pos))){
                    String packageName = paketBilgi.packageName;
                }
            }
        }
    });

But if 2 apps have same label there will be problem so it would be better if you can use   another list and store the package names and use it.

final List<String> packageNames = new Arraylist<String>();

uygList.add(paketBilgi.loadLabel(pm).toString()); 
packageNames.add(paketBilgi.packageName);

lv.setOnItemClickListener(new OnItemClickListener() {
    @Override
    public void onItemClick(AdapterView<?> parent, View view, int pos, long id) {
        String packageName =  packageNames.get(pos);
    // I want to get the packageName that selected from ListView like (com.blabla.blabla)
    }
});
于 2013-02-24T11:17:13.933 に答える
-1

public void onItemClick(AdapterView 親、View ビュー、int pos、long id) {

    // I want to get the packageName that selected from ListView like (com.blabla.blabla)

}

param pos は uygList の位置です

于 2013-02-24T11:49:00.860 に答える