0

I am trying to make my listview only one row with just imageview. Here is my adapter:

public class ListAdapter extends BaseAdapter {

private Context activity;
private ArrayList<HashMap<String, String>> data;
private static LayoutInflater inflater=null;

public ListAdapter(Context a, ArrayList<HashMap<String, String>> d) {
    activity = a;
    data=d;
    inflater = (LayoutInflater)activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}

public int getCount() {
    return data.size();
}

public Object getItem(int position) {
    return data.get(position);
}

public long getItemId(int position) {
    return position;
}

public View getView(int position, View convertView, ViewGroup parent) {
    View vi=convertView;
    if(convertView==null)
        vi = inflater.inflate(R.layout.listview, null);
    TextView subject = (TextView)vi.findViewById(R.id.subject);
    TextView added = (TextView)vi.findViewById(R.id.added); 
    TextView permalink = (TextView)vi.findViewById(R.id.permalink);

    HashMap<String, String> map = new HashMap<String, String>();
    map = data.get(position);

     //Setting all values in listview
    subject.setText(map.get(ViewPagerAdapter.KEY_NEWS_SUBJECT));
    added.setText(map.get(ViewPagerAdapter.KEY_NEWS_LAPSE));
    permalink.setText(map.get(ViewPagerAdapter.KEY_NEWS_PERMA));
    return vi;
}

}

Current layout have few textview, but the only row lets say I fix it on the 4th to display only imageview. How should I do it??

Marcin Orlowski
  • 72,056
  • 11
  • 123
  • 141
Eric
  • 1,547
  • 2
  • 18
  • 34
  • Refer to `getItemViewType(int position)` and `getViewTypeCount()` to use different layouts for the adapter's content. Have a look at [this answer](http://stackoverflow.com/a/13150279/1029225) and the links provided in there. Also, don't forget to implement the ViewHolder/RowWrapper pattern to optimize the view binding process. – MH. Nov 26 '12 at 02:17

1 Answers1

0

First add an ImageView in the custom layout.
Inside your public View getView(int position, View convertView, ViewGroup parent) method add the following:

   ImageView image = (ImageView)vi.findViewById(R.id.imageview);
    if( position == 0){ // here I suppose you want it display on the first row
         image.setVisibility(View.Visible);
    }
    else{
        image.setVisibility(View.GONE);
    }

Side note: I advise you to use a ViewHolder when using getView();

Lazy Ninja
  • 22,342
  • 9
  • 83
  • 103
  • i was trying the getItemViewType method but failed to do so, however this method are much more easier since there is only one row different. – Eric Nov 29 '12 at 07:43