2011-05-24 57 views
1

我正在開發一個應用程序,我必須在列表視圖中點擊一個項目,我已經開發了它的類,但點擊類視圖不會被調用。我不明白爲什麼?如何在listview中點擊列表項時調用新的類視圖?

這裏是我的代碼的類被稱爲

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 

    } 

和thanx提前

回答

0

你的代碼改成這樣

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

}

希望「飼料」這裏是你的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"); 

這將有助於..不要回應,如果問題仍然存在..

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

       } 
      }); 
相關問題