Я переопределил метод getView()
в ArrayAdapter
. Мне было интересно, есть ли способ сохранить функциональность флажка при переопределении getView()
?переопределить getView в ArrayAdapter и по-прежнему держать флажки?
С моей текущей реализацией оно отображает только изображение и текст в каждой строке. Он больше не показывает флажки, которые были там до переопределения.
Ниже мой код:
public class ShortcutsArrayAdapter extends ArrayAdapter<ResolveInfo> {
private final Activity context;
private final List<ResolveInfo> objects;
private PackageManager pm = null;
public ShortcutsArrayAdapter(Activity context, int textViewResourceId,
List<ResolveInfo> objects, PackageManager pm) {
super(context, textViewResourceId, objects);
this.context = context;
this.objects = objects;
this.pm = pm;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater inflator = context.getLayoutInflater();
View rowView = inflator.inflate(R.layout.rowlayout, null, true);
TextView textView = (TextView) rowView.findViewById(R.id.label);
ImageView imageView = (ImageView) rowView.findViewById(R.id.icon);
textView.setText(objects.get(position).loadLabel(pm));
try {
imageView.setImageBitmap(((BitmapDrawable) pm.getApplicationIcon(objects.get(position).activityInfo.applicationInfo.packageName)).getBitmap());
} catch (NameNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return rowView;
}
}
А вот как я творю адаптер:
appList = getApplicationList();
setListAdapter(new ShortcutsArrayAdapter(this, android.R.layout.simple_list_item_multiple_choice, appList, pm));
getListView().setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
Вот макет строки XML:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<ImageView
android:id="@+id/icon"
android:layout_width="40dp"
android:layout_height="40dp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/label"
android:text="@+id/label"/>
</LinearLayout>
При добавлении 'super.getView (position, convertView, parent);' к методу. Это ошибка, которую я получаю от logcat при запуске. '02-14 15: 44: 48.924: E/AndroidRuntime (26397): java.lang.IllegalStateException: ArrayAdapter требует, чтобы идентификатор ресурса был TextView'. Я изменил его на какой-то случайный «TextView», и он все еще не работал. Он сказал 'invalid resource'. – prolink007
@ prolink007 Где установлен флажок в вашем row_layout.xml :) ?? – Sid
OoooooooooopSSSSS! Забыл поставить флажок в моем xml. Больше глаз лучше. Спасибо. – prolink007