java 子listview,java – Android:添加ListView子项文本

我创建了一个RSS阅读器列出列表视图中的项目。我也想在每个项目下面有一个日期,但我不知道如何做到这一点。我需要某人的帮助,使子项目文本显示从RSS提要检索的pubDate。

这是我为我的类的代码:

public class RSSReader extends Activity implements OnItemClickListener

{

public final String RSSFEEDOFCHOICE = "http://app.calvaryccm.com/mobile/android/v1/devos";

public final String tag = "RSSReader";

private RSSFeed feed = null;

/** Called when the activity is first created. */

public void onCreate(Bundle icicle) {

super.onCreate(icicle);

setContentView(R.layout.main);

// go get our feed!

feed = getFeed(RSSFEEDOFCHOICE);

// display UI

UpdateDisplay();

}

private RSSFeed getFeed(String urlToRssFeed)

{

try

{

// setup the url

URL url = new URL(urlToRssFeed);

// create the factory

SAXParserFactory factory = SAXParserFactory.newInstance();

// create a parser

SAXParser parser = factory.newSAXParser();

// create the reader (scanner)

XMLReader xmlreader = parser.getXMLReader();

// instantiate our handler

RSSHandler theRssHandler = new RSSHandler();

// assign our handler

xmlreader.setContentHandler(theRssHandler);

// get our data via the url class

InputSource is = new InputSource(url.openStream());

// perform the synchronous parse

xmlreader.parse(is);

// get the results - should be a fully populated RSSFeed instance, or null on error

return theRssHandler.getFeed();

}

catch (Exception ee)

{

// if we have a problem, simply return null

System.out.println(ee.getMessage());

System.out.println(ee.getStackTrace());

System.out.println(ee.getCause());

return null;

}

}

public boolean onCreateOptionsMenu(Menu menu)

{

super.onCreateOptionsMenu(menu);

menu.add(Menu.NONE, 0, 0, "Refresh");

Log.i(tag,"onCreateOptionsMenu");

return true;

}

public boolean onOptionsItemSelected(MenuItem item){

switch (item.getItemId()) {

case 0:

Log.i(tag,"Set RSS Feed");

return true;

case 1:

Log.i(tag,"Refreshing RSS Feed");

return true;

}

return false;

}

private void UpdateDisplay()

{

TextView feedtitle = (TextView) findViewById(R.id.feedtitle);

TextView feedpubdate = (TextView) findViewById(R.id.feedpubdate);

ListView itemlist = (ListView) findViewById(R.id.itemlist);

if (feed == null)

{

feedtitle.setText("No RSS Feed Available");

return;

}

if(feedtitle != null)

feedtitle.setText(feed.getTitle());

if(feedpubdate != null)

feedpubdate.setText(feed.getPubDate());

ArrayAdapter adapter = new ArrayAdapter(this,android.R.layout.simple_list_item_1,feed.getAllItems());

itemlist.setAdapter(adapter);

itemlist.setOnItemClickListener(this);

itemlist.setSelection(0);

}

@Override

public void onItemClick(AdapterView parent, View v, int position, long id)

{

//Log.i(tag,"item clicked! [" + feed.getItem(position).getTitle() + "]");

Intent itemintent = new Intent(this,ShowDescription.class);

Bundle b = new Bundle();

b.putString("title", feed.getItem(position).getTitle());

b.putString("description", feed.getItem(position).getDescription());

b.putString("link", feed.getItem(position).getLink());

b.putString("pubdate", feed.getItem(position).getPubDate());

itemintent.putExtra("android.intent.extra.INTENT", b);

startActivity(itemintent);

}

}

这是我的XML:

android:orientation="vertical"

android:layout_width="fill_parent"

android:layout_height="fill_parent">

android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:text="Android RSSReader"

android:id="@+id/feedtitle"/>

android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:text=""

android:id="@+id/feedpubdate"/>

android:layout_width="fill_parent"

android:layout_height="fill_parent"

android:id="@+id/itemlist"

android:fastScrollEnabled="true"/>

这就是现在在Eclipse中的样子:

这是它看起来像运行:

我需要某人的帮助,使子项目文本显示从RSS提要检索的pubDate。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值