меня MainActivity, какКак заменить текущий вид фрагмента с другой точкой зрения фрагмента
listViewFragment = new ListViewFragment();
getFragmentManager().beginTransaction().add(R.id.fragmentSensors, listViewFragment).commit();
Тогда я ListViewFragment и ListViewAdapter класс, определенный, который работает отлично.
listViewSensors.setAdapter(new ListViewAdapter(getActivity(), sensorArray));
Но когда я определяю onClicklistener, текущий вид не заменяется новым видом фрагмента.
Здесь представлены файлы макета. activity_main
<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">
<fragment android:id="@+id/fragmentSensors" android:layout_width="match_parent"
android:layout_height="match_parent"
android:name="com.testapp.fragment.ListViewFragment"/>
</RelativeLayout>
listview_fragment
<LinearLayout 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">
<ListView android:id="@+id/listViewSensors" android:layout_width="match_parent"
android:layout_height="match_parent"
/>
</LinearLayout>
listview_adapter имеет ImageView и TextView.
И тогда я определил test_fragment, как
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_height="match_parent">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="Hello Test"
android:id="@+id/textViewTest"/>
</LinearLayout>
и назвал его через ListViewFragment в
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
accelFragment = new AccelFragment();
testFragment = new TestFragment();
getFragmentManager().beginTransaction().replace(R.id.fragmentSensors, testFragment).commit();
Toast.makeText(getActivity(),"Ok", Toast.LENGTH_SHORT).show();
}
Но ничего не происходит, я вижу Тост всплывающее окно, хотя. Если я использую android.R.id.content. Я вижу новый текст поверх текущих элементов listView. Если я использую R.id.listViewSensors я получаю ошибкуjava.lang.UnsupportedOperationException: addView(View) is not supported in AdapterView
Или мне нужно продлить действие и использовать намерение позвонить? – user2661518
Кажется, проблема может быть с классом TestFragment. –