2013-11-11 3 views
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; 
} 




     } 
+0

показать свой код, где вы установилиAdapter() – QuokMoon

+0

ListView lis = (ListVi ЭВ) findViewById (R.id.list); Sadapter A = новый Sadapter (это, R.layout.newfeed_layout, NewsObjs); lis.setAdapter (A); –

ответ

0

Попробуйте внедрить методы геттера для адаптера массива. Я думаю, что это может быть источником вашей проблемы ..

+0

Адаптер массива будет искать методы getter, такие как getItemId(), getItem(), getCount() и getPosition(). Поэтому попробуйте переопределить эти методы. – Sripathi

+0

i do doest work –

+0

Изменить строку View row = inflater.inflate (R.layout.newfeed_layout, parent, false); as Показать строку = inflater.inflate (R.layout.newfeed_layout, null); – Sripathi

0

Изменить метод getView()

@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; 
    } 
+0

не работает –

0
View row=inflater.inflate(R.layout.newfeed_layout,parent,false); 

должен быть этот

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

, если вы используете какой-то макет для каждой строки (например list_row.xml)

Смежные вопросы