0

我试图让我的列表视图只有一行,只有 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。我该怎么做??

4

1 回答 1

0

首先在自定义布局中添加一个 ImageView。
在您的public View getView(int position, View convertView, ViewGroup parent)方法中添加以下内容:

   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);
    }

旁注:我建议您在使用 getView(); 时使用 ViewHolder;

于 2012-11-26T03:03:52.383 回答