我有一个应用程序,可以从中获取所有已安装应用程序及其图标的列表。这是我的代码:
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));
}
}
但现在我希望如果我点击一个列表项,那么该特定应用程序将从下一次开始以横向打开,我需要想法我该怎么做?