1

我在android中有一個片段佈局。左側窗格中有一個listfragment,其中包含選項列表,右側窗格具有特定於從左側listfragment窗格中選擇的項目的詳細信息或表單。現在直到這我已完成和它的工作但我想要的是右側窗格中的窗體應該有一些按鈕和其他控件,並單擊按鈕「查看信息」不同的佈局應該在同一個地方即細節窗格區。現在有一件事是,具有「查看信息」按鈕的佈局的詳細信息區域是DetailsFragment中的膨脹佈局。公共查看onCreateView()方法。在細節中顯示不同的佈局片段

@Override 
public View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle savedInstanceState) { 
     if (container == null) {    
     return null; 
    }  


     View v = inflater.inflate(R.layout.listviewitems, null); 


     ListView lv = (ListView) v.findViewById(R.id.listv); 
     TextView tv=(TextView)v.findViewById(R.id.tvtitle); 
     Button verify=(Button)v.findViewById(R.id.button1); 

     verify.setOnClickListener(new OnClickListener() { 

     public void onClick(View v) { 

// I want to write a code for display next screen here. 
     } 

    }); 

     Bundle b = getArguments(); 
     String itemclick = null; 
     if(b.getInt("index")==0) 
     { 
      itemclick="pending order"; 
     } 
     else if(b.getInt("index")==1) 
     { 
      itemclick="orders recieved today"; 
     } 
     else if(b.getInt("index")==2) 
     { 
      itemclick="todays orders"; 
     } 
     tv.setText(itemclick); 

     populateItemlist(); 
     lv.invalidateViews();   


     return v;   
} 

你可以看到屏幕快照http://www.freeimagehosting.net/fi878。 按鈕點擊還需要在顯示下一個UI之前執行一些數據庫任務,這裏我沒有提到。但我的主要問題是如何在按鈕點擊的同一位置顯示不同的佈局。 Plz幫助我作爲新的android。

回答

0

使用FragmentTransaction,並用新的Fragment替換舊的Fragment。

FragmentTransaction ft = getFragmentManager().beginTransaction(); 

DetailsFragment newFragment = DetailsFragment.newInstance(); 
ft.replace(R.id.details_fragment_container, newFragment, "detailFragment"); 
ft.commit(); 
+0

而這是它強制宣佈在我的mainactivity.xml中的每個佈局的片段?因爲我放在這裏的代碼是一個類public class DetailsFragment extends Fragment – user1661935