2014-09-29 12 views
-3

任何人都可能給我一個完整的示例來演示ListView。 listview中的每個項目都需要激發一個新的活動。 例如,如果我使用'主題'作爲ListView的內容,那麼在按下列表視圖中的特定主題後,會顯示一個新的屏幕及其標題和該主題的一些內容。 我知道這是太多要問,但我一直在尋找ListView Ex。因爲相當長,迄今爲止沒有任何幫助。 PLease幫助 謝謝ListView示例程序切換到新的活動

+0

使用'開關case'在''的ListView onItemClick'方法及其'position' '。 – Piyush 2014-09-29 13:08:10

+0

http://stackoverflow.com/a/23994445/2413303 – EpicPandaForce 2014-09-29 13:09:38

+0

說實話,只需創建一個最小SDK級別爲11和目標SDK 19的新項目,並且導航類型爲「主/細節流」,您將擁有你的答案。 o.o – EpicPandaForce 2014-09-29 13:13:46

回答

0

你可以參考下面的鏈接listview演示代碼。

http://www.androidhive.info/2011/10/android-listview-tutorial/

和關於選擇任何項目打開新的活動,你可以使用,

listCoupon.setOnItemClickListener(new OnItemClickListener() { 

     @Override 
     public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, 
       long arg3) { 
      // TODO Auto-generated method stub 

      // here you can compare selected item by its position and then start a new activity 

// arg2 is selected item position in your arraylist 

     } 

    }); 
+0

該代碼正在工作,但無法切換到下一個屏幕.. – Shrujan 2014-09-29 13:31:20

+0

你可以寫Intent myIntent = new Intent(CurrentActivity.this,,NextActivity.class); startActivity(myIntent); – Beena 2014-09-29 16:06:52

0
yourlistview.setOnItemClickListener(new OnItemClickListener() { 
      @Override 
      public void onItemClick(AdapterView<?> parent, View view, 
        int position, long id) { 


      } 
      }); 

then use bundle to send some content to your next activity. 
then getActionBar.setTitle(sometext); this text is come from your bundle. 

This contains: 
http://www.androidbegin.com/tutorial/android-search-listview-using-filter/