0

我有一个自定义对象(NewsFeedObj)的数组列表。我想使用 NewsFeedObj 中的变量填充列表视图。当我运行代码时,我得到一个空白屏幕。怎么了?

 class Sadapter extends ArrayAdapter<NewsFeedObj>
  {
  Context context;
   int j;
    NewsFeedObj o = new NewsFeedObj();
     ArrayList<NewsFeedObj> l;
public Sadapter(Context context,int i,ArrayList<NewsFeedObj> g) 
{
    super(context,i,g);
    this.context=context;
    this.l=g;
    this.j=i;

    // TODO Auto-generated constructor stub
}

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    // TODO Auto-generated method stub

    LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    View row=inflater.inflate(R.layout.newfeed_layout,parent,false);
    //row.findViewById(id)
    TextView Text=(TextView) row.findViewById(R.id.Description);
    o=l.get(position);
    Text.setText( o.get_description());


    return row;
}




        }
4

3 回答 3

0

Change the getView() method

@Override
    public View getView(int position, View convertView, ViewGroup parent) {
        // TODO Auto-generated method stub
        View row= convertView;
        if (view == null) {// Added check
        LayoutInflater inflater = (LayoutInflater)   context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        row=inflater.inflate(R.layout.newfeed_layout,parent,false);
        }
        NewsFeedObj  o=l.get(position);// Changed here
        TextView Text=(TextView) row.findViewById(R.id.Description);

        Text.setText( o.get_description());


        return row;
    }
于 2013-11-11T05:42:00.400 回答
0
View row=inflater.inflate(R.layout.newfeed_layout,parent,false);

should be this

View row=inflater.inflate(list_row.xml,null);

if you are using some layout for each row (for example list_row.xml)

于 2013-11-11T05:42:18.633 回答
0

尝试为数组适配器实现 getter 方法。我认为这可能是您问题的根源..

于 2013-11-11T05:38:30.430 回答