0
システムアプリ以外のすべてのインストール済みアプリケーションでスピナーを作成しようとしています。アンドロイドスピナーのデータを繰り返しました
1)私はは私のスピナーが移入されデータ
2)を繰り返し取得していますし、私はスピナー項目のリストを開き、時にはギャップが存在することができで間:私は2つの問題に実行していますよアプリ名。
以下の私のアダプタのコードを参照してください:上記の二つのどちらかに任意のヘルプ
public class PackageAdapter extends BaseAdapter implements SpinnerAdapter {
private List<ApplicationInfo> applications;
private Context context;
private PackageManager packageManager = null;
public PackageAdapter(Context context) {
this.context = context;
// setting up the List applications with all the list of installed apps
applications = new ArrayList<ApplicationInfo>();
try {
packageManager = context.getPackageManager();
if (packageManager != null) {
applications = packageManager.getInstalledApplications(0);
}
} catch (Exception e) {
Log.e("error", e.getMessage());
}
}
@Override
public int getCount() {
return applications.size();
}
@Override
public Object getItem(int position) {
return applications.get(position);
}
@Override
public long getItemId(int position) {
return applications.indexOf(getItem(position));
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View spinView;
if (convertView == null) {
// setting up the view
LayoutInflater inflater = (LayoutInflater)
context.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
spinView = inflater.inflate(R.layout.spin_layout, null);
} else {
spinView = convertView;
}
// getting one application from the list of apps.
final ApplicationInfo application = this.applications.get(position);
// filtering out the system apps and getting the application name
String appName = "";
if (packageManager.getLaunchIntentForPackage(application.packageName) != null) {
appName = packageManager.getApplicationLabel(application).toString();
}
TextView t1 = (TextView) spinView.findViewById(R.id.field1);
if (!appName.equals("")) {
t1.setText(appName);
}
return spinView;
}
}
をいただければ幸いです! TY
内のすべてのパッケージ?@デビッドジャービス –
こんにちは@Amit Vaghela Tyのあなたのポストのための&これで助けて!だから私はあなたのアダプタコードをあなたのものに置き換えました。私のスピナーはアプリケーション名ではなくすべてのパッケージ名を表示しています。スピナーにはシステムアプリが入っています。私のスピナー項目は、ユーザーがアプリのパッケージ名を知らないため、アプリ名として表示する必要があります。また、このリストからシステムアプリを選択することもできません。これに合うようにコードを修正する方法は? –
更新された回答を確認してください。あなたの問題は解決されました@ DavidJarvis –