2016-02-22 90 views
-1

我是一個嘗試在android studio的新手。如何將我的內容放入第1部分以及第2部分中的其他內容等(我創建了選項卡式活動) 我的意思是,預製的代碼允許我只編輯字符串,並將其放置在所有選項卡中。我如何僅選擇第一頁並插入內容? 任何幫助如何將文本放在Android工作室中的java選項卡活動

樣品:

/** 
* A placeholder fragment containing a simple view. 
*/ 
public static class PlaceholderFragment extends Fragment { 
    /** 
    * The fragment argument representing the section number for this 
    * fragment. 
    */ 
    private static final String ARG_SECTION_NUMBER = "section_number"; 

    public PlaceholderFragment() { 
    } 

    /** 
    * Returns a new instance of this fragment for the given section 
    * number. 
    */ 
    public static PlaceholderFragment newInstance(int sectionNumber) { 
     PlaceholderFragment fragment = new PlaceholderFragment(); 
     Bundle args = new Bundle(); 
     args.putInt(ARG_SECTION_NUMBER, sectionNumber); 
     fragment.setArguments(args); 
     return fragment; 
    } 

    @Override 
    public View onCreateView(LayoutInflater inflater, ViewGroup container, 
          Bundle savedInstanceState) { 
     View rootView = inflater.inflate(R.layout.fragment_main, container, false); 
     TextView textView = (TextView) rootView.findViewById(R.id.section_label); 
     textView.setText(getString(R.string.section_format, getArguments().getInt(ARG_SECTION_NUMBER))); 
     return rootView; 
    } 
} 

的strings.xml:

<resources> 
<string name="app_name">App name</string> 
<string name="action_settings">Settingsy</string> 
<string name="section_format">Section text. Taken from strings.xml</string> 

project screenshot on a device

回答

1

創建兩個片段e.g片段1和Fragment2。爲fragment1和fragment2創建兩個xml佈局,並在相應的片段中膨脹。然後分配每個片段到相應的選項卡。按照此LINK。這會幫助你很多。

相關問題