Я начинаю разработку Android, и я получаю эту ошибку в заголовке.
Вот мои Contacts.java
package us.inevent.toot;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v7.app.ActionBarActivity;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
public class Contacts extends ActionBarActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_contacts);
if (savedInstanceState == null) {
getSupportFragmentManager().beginTransaction()
.add(R.id.container, new ContactListFragment()).commit();
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.contacts, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
/**
* A placeholder fragment containing a simple view.
*/
public static class ContactListFragment extends Fragment {
private ViewGroup listContacts;
public ContactListFragment() {
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState)
{
View rootView = inflater.inflate(R.layout.fragment_contacts,
container, false);
listContacts = (ViewGroup) rootView.findViewById(R.id.listContacts);
TextView aux = new TextView(getActivity());
aux.setText("Hello World!");
listContacts.addView(aux);
return rootView;
}
}
}
Внутри метода onCreateView()
моего ContactListFragment
я создаю TextView
с текстом "Hello World".
Затем я пытаюсь добавить этот вид в мой ViewGroup
listContacts.
Вот мой fragment_contacts.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"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="us.inevent.toot.Contacts$PlaceholderFragment" >
<TextView
android:id="@+id/textContact"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="0dp"
android:text="@string/textContact"
android:textSize="@dimen/abc_action_bar_title_text_size" />
<ListView
android:id="@+id/listContacts"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/textContact"
android:layout_marginTop="10dp" />
</RelativeLayout>
Что я делаю неправильно?
Спасибо.