J'ai une application qui me permet d'obtenir la liste de toutes les applications installées avec leur icône. Voici mon code :
package com.powergroupbd.appfilter;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.Iterator;
import java.util.List;
import android.app.Activity;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.util.Log;
import android.widget.ArrayAdapter;
import android.widget.ListView;
public class ApplicationFilterActivity extends Activity {
/** Called when the activity is first created. */
ListView appfilter;
// ArrayAdapter<Applications> adapter;
PackageManager pck;
ArrayList<Applications> results = new ArrayList<Applications>();
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
appfilter = (ListView) findViewById(R.id.lvApp);
PackageManager packageManager = this.getPackageManager();
List<PackageInfo> applist = packageManager.getInstalledPackages(0);
Iterator<PackageInfo> it = applist.iterator();
while (it.hasNext()) {
PackageInfo pk = (PackageInfo) it.next();
results.add(new Applications(pk.applicationInfo.loadIcon(packageManager), ""+pk.applicationInfo.loadLabel(packageManager)));
Log.i("AppName", ""+pk.applicationInfo.loadLabel(packageManager));
}
Collections.sort(results, new Comparator<Applications>() {
@Override
public int compare(Applications c1, Applications c2) {
return c1.getAppname().compareToIgnoreCase(c2.getAppname());
}
});
appfilter.setAdapter(new Customarrayadapter(this, results));
}
}
Mais maintenant, je veux que si je clique sur un élément de la liste, cette application particulière s'ouvre en orientation Paysage la prochaine fois, j'ai besoin d'une idée pour faire cela.