我想在每一個列表視圖兩行item.this是我的代碼,但它不工作...2號線在ListView項目
RE-編輯的代碼
public class nea extends ListActivity{
private List<Message> messages;
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.main2);
loadFeed(ParserType.DOM);
}
private void loadFeed(ParserType type){
try{
Log.i("News", "ParserType="+type.name());
FeedParser parser = FeedParserFactory.getParser(type);
long start = System.currentTimeMillis();
messages = parser.parse();
long duration = System.currentTimeMillis() - start;
Log.i("News", "Parser duration=" + duration);
String xml = writeXml();
Log.i("News", xml);
List<String> titles = new ArrayList<String>(messages.size());
for (Message msg : messages){
String o = titles.get(messages.size());
if (o != null) {
TextView tt = (TextView) findViewById(R.id.TextView01);
TextView bt = (TextView) findViewById(R.id.TextView02);
if (tt != null) {
titles.add(""+msg.getDate()); }
if(bt != null){
titles.add("date: "+ msg.getTitle());
}return;
//titles.add(msg.getDate()+"\n"+msg.getTitle());
}
// titles.add(msg.getTitle()+" "+msg.getDate());
}
ArrayAdapter<String> adapter =
new ArrayAdapter<String>(this, R.layout.row,titles);
this.setListAdapter(adapter);
// textView.setText(Html.fromHtml(titles.get(position)));
} catch (Throwable t){
Log.e("News",t.getMessage(),t);
}
}
第二WAY- - 不是工作壓力太大
List<String> titles = new ArrayList<String>(messages.size());
for (Message msg : messages){
String o = titles.get(messages.size());
if (o != null) {
TextView tt = (TextView) findViewById(R.id.TextView01);
TextView bt = (TextView) findViewById(R.id.TextView02);
if (tt != null) {
titles.add(""+msg.getDate()); }
if(bt != null){
titles.add("date: "+ msg.getTitle());
}return;
//titles.add(msg.getDate()+"\n"+msg.getTitle());
}
// titles.add(msg.getTitle()+" "+msg.getDate());
}
ArrayAdapter<String> adapter =
new ArrayAdapter<String>(this, R.layout.row,titles);
this.setListAdapter(adapter);
// textView.setText(Html.fromHtml(titles.get(position)));
} catch (Throwable t){
Log.e("News",t.getMessage(),t);
}
你需要發佈的所有代碼本,其並不清楚自己在做什麼在那裏。什麼是信息?你如何設置數據源,適配器和列表視圖? – Jems 2011-01-29 16:17:29
好吧,我發佈了更多代碼sir – 2011-01-29 16:21:09