0
我想讓我的listview只有一行imageview。這裏是我的適配器:設置列表視圖只有一行差異
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;
}
}
當前佈局有幾個TextView的,但唯一的行可以說我修復4號,僅顯示ImageView的。我應該怎麼做?
請參考'getItemViewType(int position)'和'getViewTypeCount()'來爲適配器的內容使用不同的佈局。看看[這個答案](http://stackoverflow.com/a/13150279/1029225)和那裏提供的鏈接。另外,不要忘記實現ViewHolder/RowWrapper模式來優化視圖綁定過程。 –