开发者

how to call a new class view on click of a list item in listview?

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(Adapt开发者_C百科erView 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


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..


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

                }
            });
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜