i have a list defined by the layout list_item_new.xml in which i have an imageView and 2 textViews. ImageView is defined like this
<ImageView
android:id="@+id/listimage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
android:src="@drawable/users2"
/>
i am using the same ListView on 3 different screens. Now what i want is that the image on this imageView should be different for all the 3 screens. i am trying to change to image like this
LayoutInflater inflater = (LayoutInflater) this.getSystemService
(Context.LAYOUT_INFLATER_SERVICE);
LinearLayout ll = (LinearLayout) inflater.inflate(R.layout.list_item_new, null);
listimg=(ImageView)ll.findViewById(R.id.listimage);
listimg.setImageResource(R.drawable.office);
office.png is an image in drawable.
the whole code is executing but the image is not changing. please tell me what should i do to change the image. i am writing this code in onCreate method of activity and after this i am assigning the data to the list
thanks
see this class
public class Adapter extends SimpleAdapter{
public Adapter(Context context, List<? extends Map<String, String>> data,
int resource, String[] from, int[] to) {
super(context, data, resource, from, to);
}
@Override
public View getView(int position, View convertView, ViewGroup parent){
View row = convertView;
if (row == null) {
LayoutInflater inflater = (LayoutInflater) this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
row ll = inflater.inflate(R.layout.list_item_new, null);
listimg=(ImageView)ll.findViewById(R.id.listimage);
listimg.setImageResource(R.drawable.office);
textView=(TextView)ll.findViewById(R.id.<textViewID>);
textView.setText("Hello");
}
return row;
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.