如何在单击列表视图中的列表项时调用新的类视图?

发布于 2024-11-09 12:13:48 字数 915 浏览 0 评论 0原文

我正在 Android 中开发一个应用程序,我必须在单击列表视图中的项目时调用一个类。我已经为其开发了类,但单击时不会调用类视图。我不明白为什么?

这是我要调用的类的代码

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

         startSubActivity(itemintent,0);
     }


    private void startSubActivity(Intent itemintent, int i) {
        // TODO Auto-generated method stub

    }

,并提前感谢

i am developing an application in android for which i have to call a class on click of an item in list view.i have developed the classes for it but on click the class view is not called. I can't understand why?

here is my code for the class to be called

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

         startSubActivity(itemintent,0);
     }


    private void startSubActivity(Intent itemintent, int i) {
        // TODO Auto-generated method stub

    }

and thanx in advance

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

比忠 2024-11-16 12:13:48

将您的代码更改为此

public void onItemClick(AdapterView parent, View v, int position, long id)
{
ListView feed = (ListView) findViewById(R.id.yourID);
Intent itemintent = new Intent(this,ShowDescription.class);

 itemintent.putExtra("title", feed.getItemAtPosition(position).getTitle());
 itemintent.putExtra("description", feed.getItemAtPosition(position).getDescription());
 itemintent.putExtra("link", feed.getItemAtPosition(position).getLink());
 itemintent.putExtra("pubdate", feed.getItemAtPosition(position).getPubDate());

 startActivity(itemintent);

}

我希望这里的“feed”是您的ListView。当您想在下一个活动中获取值时,请使用以下命令:-

 Bundle extra= getIntent().getExtras();
 String title = extra.getString("title");
 String description = extra.getString("description");
 String link = extra.getString("link");
 String pubdate = extra.getString("pubdate");

这会有所帮助..如果问题仍然存在,请回复..

Change your code to this

public void onItemClick(AdapterView parent, View v, int position, long id)
{
ListView feed = (ListView) findViewById(R.id.yourID);
Intent itemintent = new Intent(this,ShowDescription.class);

 itemintent.putExtra("title", feed.getItemAtPosition(position).getTitle());
 itemintent.putExtra("description", feed.getItemAtPosition(position).getDescription());
 itemintent.putExtra("link", feed.getItemAtPosition(position).getLink());
 itemintent.putExtra("pubdate", feed.getItemAtPosition(position).getPubDate());

 startActivity(itemintent);

}

I hope the "feed" here is your ListView. When you want to get the values in your next activity use the following:-

 Bundle extra= getIntent().getExtras();
 String title = extra.getString("title");
 String description = extra.getString("description");
 String link = extra.getString("link");
 String pubdate = extra.getString("pubdate");

This will help.. Do reply if the problem still persists..

黎歌 2024-11-16 12:13:48
listview.setOnItemClickListener(new OnItemClickListener() {

                @Override
                public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
                        long arg3) {


                    Intent arDetail = new Intent(this,ShowDescription.class);
                    arDetail.putString("title", feed.getItem(position).getTitle());
    arDetail.putString("description", feed.getItem(position).getDescription());
    arDetail.putString("link", feed.getItem(position).getLink());
   arDetail.putString("pubdate", feed.getItem(position).getPubDate());
                    startActivity(arDetail);

                }
            });
listview.setOnItemClickListener(new OnItemClickListener() {

                @Override
                public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
                        long arg3) {


                    Intent arDetail = new Intent(this,ShowDescription.class);
                    arDetail.putString("title", feed.getItem(position).getTitle());
    arDetail.putString("description", feed.getItem(position).getDescription());
    arDetail.putString("link", feed.getItem(position).getLink());
   arDetail.putString("pubdate", feed.getItem(position).getPubDate());
                    startActivity(arDetail);

                }
            });
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文