I have overrode the getView() method in ArrayAdapter. I was wondering if there was a way to keep the check box functionality when overriding getView()?
With my current implementation, it only shows the image and the text on each row. It no longer shows the checkboxes that were there before overriding.
Below is my code:
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;
}
}
And here is how i am creating the adapter:
appList = getApplicationList();
setListAdapter(new ShortcutsArrayAdapter(this, android.R.layout.simple_list_item_multiple_choice, appList, pm));
getListView().setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
Here is the row layout 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>
Why don’t you call super.getView() and after that do some of the custom stuff you want to do?
In any case, I don’t see why the checkbox shouldn’t show. Maybe it is hidden behind another component. Have you checked the layout? Try moving it before or after the text box.
You may need a checkbox in your row_layout.xml. Something like the following: