2014-02-09 2 views
0

Буквально самое основное приложение происходит, просто изучая. Я создал новый XML-файл для нового макета, добавил некоторые вещи, и я изменил свой setContentView() в MainActivity, чтобы соответствовать, и у меня возникли проблемы с его работой. Вот мой код.Android Noob, макет не работает

Мои OnCreate():

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

    if (savedInstanceState == null) { 
     getSupportFragmentManager().beginTransaction() 
       .add(R.id.container, new PlaceholderFragment()) 
       .commit(); 
    } 
} 

и мой XML new_layout:

<?xml version="1.0" encoding="UTF-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="horizontal" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    > 

    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="New Text" 
     android:id="@+id/textView" /> 

    <EditText 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:id="@+id/editText" 
     android:layout_weight="1" 
     android:inputType="text" /> 

    <Button 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="New Button" 
     android:id="@+id/button" /> 
</LinearLayout> 

Legit просто пытается заставить его работать.

Ошибка:

java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.androidsdk.demo/com.example.androidsdk.demo.MainActivity}: java.lang.IllegalArgumentException: No view found for id 0x7f07003c (com.example.androidsdk.demo:id/container) for fragment PlaceholderFragment{4267dc90 #0 id=0x7f07003c} 

EDIT:

enter image description here

Спасибо :)

ответ

0

Похоже, вы не имеете заполнитель для вашего фрагмента. Вам нужно будет разместить фрагмент в представлении, чтобы его отобразить.

Смежные вопросы