2013-11-26 218 views
0

使用android studio我試圖創建自定義ListView。該應用程序不會崩潰,但我沒有items,我試圖在我的ListView上顯示。當我在這裏運行時,它是一個list,但在行中沒有任何內容。我也可以滾動它,我可以點擊沒有問題的行。 這裏是我的ListViewMainActivity創建自定義列表視圖

CustomList adapter = new CustomList(this,myRssFeed.getList()); 
       adapter.addAll(); 
       setListAdapter(adapter); 

CustomAdapter

public class CustomList extends ArrayAdapter<RSSItem> { 

private final Activity context; 
private final List<RSSItem> web; 

public CustomList(Activity context, List<RSSItem> web) { 
    super(context, R.layout.list_item, web); 
    this.context = context; 
    this.web = web; 
} 

@Override 
public View getView(int position, View view, ViewGroup parent) { 
    LayoutInflater inflater = context.getLayoutInflater(); 
    View rowView = inflater.inflate(R.layout.list_item, null, true); 

    TextView txtTitle = (TextView) rowView.findViewById(R.id.item); 
    txtTitle.setText((CharSequence) getTitle()); 

    return rowView; 
} 

private RSSItem getTitle() { 
    return null; 
} 

回答

1

嘗試更新的變化如下

TextView txtTitle = (TextView) rowView.findViewById(R.id.item); 
txtTitle.setText(web.get(pos).getTitle()); 
+0

非常感謝你,那工程:) – Rick

0

這樣的:

private RSSItem getTitle() { 
    return null; 
} 

要:

private RSSItem getTitle(int position) { 
    return web.get(position); 
} 

並改變這一點:

txtTitle.setText((CharSequence) getTitle()); 

要:

txtTitle.setText((CharSequence) getTitle(position));