2013-04-01 184 views

回答

0

我假設你正在從數據庫中獲取演員的列表和詳細信息。 我已經在我的應用程序中使用了相同的步驟來顯示所選食譜的食譜細節。

public class ActorList extends Activity { 

     ListView myActorList=null; 

public final static String selectedActor_ID="will Keep Actor ID"; 

     @Override 
     protected void onCreate(Bundle savedInstanceState) { 
      super.onCreate(savedInstanceState); 

     setContentView(R.layout.layout_actor_list);  

     //initialize controls 

      myActorList.setAdapter(adapter); 

      myActorList.setOnItemClickListener(new OnItemClickListener() { 

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


        Intent i= new Intent(ActorList.this,ActorDetail.class); 
        // you have to pass the actor id to next activity 
        // you can get this actor id from argument of type "long" 
        i.putExtra(selectedActor_ID, String.valueOf(id)); 
        startActivity(i); 

       }   

      }); 

    } 



} 


//Other Activity To show Detail.. 

//get the ID of Selected Actor on other activity say "ActorDetail" 

public class ActorDetail extends Activity { 



    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.layout_actor_detail); 

     ActorID=getIntent().getStringExtra(ActorList.selectedActor_ID); 
// now as you have the id here for that particular actor 
//fetch the detail of that selected actor thru id and bind it to your layout.  


    } 



}  

您需要註冊在清單文件中的其他活動也是這樣

<activity 
      android:name=".otherscreenActivity" 

     </activity> 
+0

假設你希望開始另一個活動爲新的屏幕.. – Joel

+0

3>是正是我的意思.... 或您可以使用「ExpandableListView」,以顯示細節作爲孩子 – DeltaCap

+0

@Joel Sorry.Still我無法理解。而且我得到一個錯誤也..我想要什麼做的是「我有一個演員名單。例如,如果我點擊湯姆漢克,它必須導航到另一個屏幕,應該顯示他的詳細信息。 –

0

爲了得到你想要的,你可以做這樣的事情是什麼?

1>創建另一個活動在某些控件中,您可以將您的值...

2> on listclick()listview ... a> create intent and set values to pass to新活動 b>以此意圖開始新活動。在OnCreate中(新的活動 的)一>從意圖retrive值 B>填充您的使用值控制...

相關問題