переопределить getView в ArrayAdapter и сохранить флажки? - PullRequest
1 голос
/ 15 февраля 2012

Я переопределил метод getView() в ArrayAdapter.Мне было интересно, есть ли способ сохранить функциональность флажка при переопределении getView()?

В моей текущей реализации он показывает только изображение и текст в каждой строке.Он больше не показывает флажки, которые были там до переопределения.

Ниже мой код:

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>

1 Ответ

1 голос
/ 15 февраля 2012

Почему бы вам не вызвать super.getView (), а после этого сделать некоторые пользовательские вещи, которые вы хотите сделать?В любом случае, я не понимаю, почему флажок не должен отображаться.Может быть, это скрыто за другим компонентом.Вы проверили макет?Попробуйте переместить его до или после текстового поля.

Вам может понадобиться флажок в вашем row_layout.xml.Примерно так:

<CheckBox
        android:id="@+id/check"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:layout_marginLeft="4px"
        android:layout_marginRight="10px" >
    </CheckBox>
...