有关RSSReader的IBM教程的问题

时间:2010-12-29 19:30:09

标签: android listview callback

我已经下载了一个关于如何用android开发rss的IBM Android教程。

这是网址

http://www.ibm.com/developerworks/xml/tutorials/x-androidrss/

对我来说这有点老了。我已经插入了新的泛型语法,但仍然有问题需要在这行编译

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;
        }

        feedtitle.setText(feed.getTitle());
        feedpubdate.setText(feed.getPubDate());

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

        itemlist.setAdapter(adapter);

        **itemlist.setOnItemClickListener(this);**

        itemlist.setSelection(0);

    }

    public void onItemClickListener(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);

     //Replacing startSubActivity from the example
     startActivityForResult(itemintent,0);
    }

编译器在这里给出错误:

itemlist.setOnItemClickListener(本);

任何想法?回调的正确方法是什么?

提前致谢

1 个答案:

答案 0 :(得分:0)

Cristian走在正确的轨道上,但你已经错误地命名了你的听众方法。这是错误的......

public void onItemClickListener(AdapterView<?> parent, View v, int position, long id)

应该是......

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