Reputation: 8071
How to add two images in a list item when using simple cursor adapter. i tried override setViewImage by extending SimpleCursorAdapter class.For single image no proble. But how to add two images?
MyFragment.java:
geoAdapter = new MySimpleCursorAdapter(getActivity().getApplicationContext(), R.layout.listitem_cdf_geolist, c1, new String[] {DBConstants.LATITUDE,DBConstants.LONGITUDE,DBConstants.TOLERANCE,DBConstants.IMEI,DBConstants.IMEI}, new int[] {R.id.li_cdf_tv_latitude,R.id.li_cdf_tv_longitude,R.id.li_cdf_tv_tolerance,R.id.li_cdf_icon_georemove,R.id.li_cdf_icon_geoedit},0);
geoList.setAdapter(geoAdapter);
In MySimpleCursorAdapter.java file:
@Override
public void setViewImage(ImageView imageView, String imei) {
Log.i("simple", "text->"+imei);
//Here how to set two images and set imei as tag for those images
imageView.setTag(imei);
imageView.setImageResource(R.drawable.action_edit);
final ImageView myimageView=imageView;
imageView.setOnClickListener(new OnClickListener(){
@Override
public void onClick(View v) {
Log.i("simple", "clicked");
String selectedIMEI = v.getTag().toString();
}
});
}
List Item Layout XML file :
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TextView
android:id="@+id/li_cdf_stv_latitude"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginTop="10dp"
android:text="@string/li_cdf_stv_latitude" />
<TextView
android:id="@+id/li_cdf_tv_latitude"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginTop="10dp"
android:layout_toRightOf="@id/li_cdf_stv_latitude" />
<TextView
android:id="@+id/li_cdf_stv_longitude"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@id/li_cdf_stv_latitude"
android:layout_below="@id/li_cdf_stv_latitude"
android:layout_marginTop="10dp"
android:text="@string/li_cdf_stv_longitude" />
<TextView
android:id="@+id/li_cdf_tv_longitude"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@id/li_cdf_tv_latitude"
android:layout_below="@id/li_cdf_tv_latitude"
android:layout_marginTop="10dp"
android:layout_toRightOf="@id/li_cdf_stv_longitude" />
<TextView
android:id="@+id/li_cdf_stv_tolerance"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@id/li_cdf_stv_longitude"
android:layout_below="@id/li_cdf_stv_longitude"
android:layout_marginTop="10dp"
android:text="@string/li_cdf_stv_tolerance" />
<TextView
android:id="@+id/li_cdf_tv_tolerance"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@id/li_cdf_tv_longitude"
android:layout_below="@id/li_cdf_tv_longitude"
android:layout_marginTop="10dp"
android:layout_toRightOf="@id/li_cdf_stv_tolerance" />
<ImageView
android:id="@+id/li_cdf_icon_georemove"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:contentDescription="@string/li_cdf_icon_georemove"
android:onClick="removeGeofence" />
<ImageView
android:id="@+id/li_cdf_icon_geoedit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toLeftOf="@id/li_cdf_icon_georemove"
android:contentDescription="@string/li_cdf_icon_geoedit"
android:onClick="editGeofence" />
<View
android:layout_width="1dp"
android:layout_height="30dp" >
</View>
</RelativeLayout>
UPDATE :
I tried to over ride on bindview. The images displayed for each list item. But If i set tag to each image,same tag applied to all images.Also remove icon onclick event only fires when click both edit and remove images.How to
@Override
public void bindView(View view, Context context, Cursor c) {
super.bindView(view, context, c);
ImageView geoEditIcon = (ImageView)view.findViewById(R.id.li_cdf_icon_geoedit);
geoEditIcon.setImageResource(R.drawable.action_editvehicle);
geoEditIcon.setTag(c.getString(c.getColumnIndex(DBConstants.IMEI)));
geoEditIcon.setOnClickListener(new OnClickListener(){
@Override
public void onClick(View v) {
Log.i("geolist", "geoRemoveIcon clicked");
String selectedIMEI = v.getTag().toString();
Log.i("geolist", "geoRemoveIcon selectedIMEI->"+selectedIMEI);
}
});
ImageView geoRemoveIcon = (ImageView)view.findViewById(R.id.li_cdf_icon_georemove);
geoRemoveIcon.setImageResource(R.drawable.action_removevehicle);
geoRemoveIcon.setTag(c.getString(c.getColumnIndex(DBConstants.IMEI)));
geoRemoveIcon.setOnClickListener(new OnClickListener(){
@Override
public void onClick(View v) {
Log.i("geolist", "geoRemoveIcon clicked");
String selectedIMEI = v.getTag().toString();
Log.i("geolist", "geoRemoveIcon selectedIMEI->"+selectedIMEI);
}
});
}
Upvotes: 0
Views: 406
Reputation: 4981
Try to override method bindView. This will look like:
@Override
public void bindView(View view, Context context, Cursor cursor) {
ImageView frst = (ImageView )view.findViewById(R.id.li_cdf_icon_georemove);
ImageView scnd = (ImageView )view.findViewById(R.id.li_cdf_icon_geoedit);
...
}
Upvotes: 1