2012-04-03 29 views
1

我有一個應用程序,其中一個選項卡有一個任務列表。我的意圖是,當我點擊該列表的其中一個元素時,我希望看到該任務的詳細信息。是否可以在同一頁面查看該任務的列表和詳細信息?我使用Eclipse。Android上的主細節佈局

+0

最好的解決方案是使用碎片http://developer.android.com/guide/topics/fundamentals/fragments.html – 2012-04-03 09:34:42

回答

0

你可以打開一個PopupWindow對列表視圖項目單擊並顯示所選項目的詳細信息。開放的項目一個PopupWindow點擊see

0

如果由於某種原因,你不想使用片段(例如,你不會永遠被再次使用這個觀點),你也可以做到這一點 - 容易和簡單:

這將是你的分屏佈局splitscreen.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/linearLayout1" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:orientation="horizontal" > 

    <LinearLayout 
     android:id="@+id/task_list_wrap" 
     android:layout_width="wrap_content" 
     android:layout_height="fill_parent" 
     android:orientation="vertical" 
     android:padding="2dp" > 

     <ListView 
      android:id="@+id/task_list" 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" 
      android:overScrollMode="never" > 
     </ListView> 
    </LinearLayout> 

    <LinearLayout 
     android:id="@+id/task_details" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:orientation="vertical"> 

     <TextView 
      android:id="@+id/task_details_description" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="this is description text" /> 
    </LinearLayout> 

</LinearLayout> 

而在你行動的任務列表中點擊這樣的時候你會改變任務的詳細信息面板的內容:

setContentView(R.layout.splitscreen); 
ListView taskList= (ListView) findViewById(R.id.task_list); 
TextView taskDescription = (TextView) findViewById(R.id.task_details_description); 
taskList.setOnItemClickListener(new OnItemClickListener() { 
    @Override 
    public void onItemClick(AdapterView<?> parent, View view, 
     int position, long id) { 
     int selectedTask = position; 
     updateTaskDescription(selectedTask, taskDescription); 
    } 
});