Ahmed Osama Ahmed Osama - 1 year ago 101
Android Question

Android listview how to make imageview (list item ) visible at specific position in the listview?

I'm facing a problem that I have a listview contains text and imageview, I want to make the imageview appear on the even positions only, how to make it?

That's what i mean

public View getView(final int position, View convertView, ViewGroup parent) {
if (convertView==null){
LayoutInflater inflater=activity.getLayoutInflater();

sora item=items.get(position);
TextView tv_id= (TextView) convertView.findViewById(R.id.sora_id);

//TextView tv_title= (TextView) convertView.findViewById(R.id.topic);
int colorPos = position % colors.length;
final int colorPos2 = position % colors.length;
tv_id.setTypeface(null, Typeface.BOLD);

final ImageView b= (ImageView) convertView.findViewById(R.id.list_item_btn);

b.setOnClickListener(new View.OnClickListener() {

public void onClick(View arg0) {

if (position ==2)

Toast.makeText(getContext(),"Clicked on: "+position,Toast.LENGTH_LONG).show();

return convertView;

Answer Source

Add this in getView()

final ImageView b= (ImageView)  convertView.findViewById(R.id.list_item_btn);
if (position%2!=0){
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download