2013-04-30 4 views
0

문제가 있습니다. 방금 ​​탭과 섹션을 탐색 할 수있는 앱을 만들었습니다. 어떻게하면 "main.xml"레이아웃을로드하고 텍스트보기로 새로운 선형 레이아웃을 만들지 않겠습니까? 가능합니까?탭 및 조각 안드로이드 이클립

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
tools:context=".MainActivity" 
android:background="@drawable/screenshot1" > 

<Button 
    android:id="@+id/button1" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignParentTop="true" 
    android:layout_marginTop="167dp" 
    android:text="Button" /> 

<Button 
    android:id="@+id/Button01" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignLeft="@+id/button1" 
    android:layout_below="@+id/button1" 
    android:layout_marginTop="44dp" 
    android:text="Button" /> 

+0

하고 main.xml에 내용은 다음과 같습니다

@TargetApi(Build.VERSION_CODES.HONEYCOMB) public class FirstTabFragment extends Fragment { private Activity activity; @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { this.activity = getActivity(); LinearLayout linearLayout = new LinearLayout(activity); LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT); linearLayout.setLayoutParams(params); TextView textView = new TextView(activity); textView.setText("This is a sample fragment. I am programmatically added"); linearLayout.addView(textView); return linearLayout; } } 

내 main.xml에 코드는? –

+0

편집 된 하나의 plz를 확인하고 ... 답장을 보내 주셔서 감사합니다. – Charbel

답변

1
public View onCreateView(LayoutInflater inflater, ViewGroup container, 
     Bundle savedInstanceState) { 
    if (container == null) { 
     return null; 
    } 
    return (RelativeLayout) inflater.inflate(R.layout.main, container,false); 
} 
+0

대단히 감사합니다. ... 내 하루를 보냈습니다. – Charbel

0
final LayoutInflater inflater = (LayoutInflater)getSystemService("layout_inflater"); 
TextView textView = (TextView)inflater.inflate(R.layout.main,null);