У меня есть фрагмент в Tabbed Activity, который создает новый вид при нажатии кнопки, проблема в том, что при создании представления и заполнении информации различной информацией, и я сажусь на другой фрагмент, а затем назад все представления, которые когда создаются с помощью кнопки, теперь содержат ту же информацию.Динамические представления не сохраняют ввод
В фрагменте:
@Override
public View onCreateView(final LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
if(view == null) {
view = inflater.inflate(R.layout.fragment_create_history, container, false);
}
Button addHistoryButton = (Button) view.findViewById(R.id.buttonAddHistory);
inflaterM = LayoutInflater.from(view.getContext());
root = (LinearLayout) view.findViewById(R.id.linearLayoutHistory);
mListener.onFragmentHistoryInteractionLoad();
addHistoryButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
View child = inflater.inflate(R.layout.list_history_layout, null);
child.setId(View.generateViewId());
root.addView(child);
}
});
return view;
}
R.layout.list_history_layout:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="5dp"
android:layout_marginTop="5dp"
android:id="@+id/linearLayoutHistory">
<View
android:layout_width="fill_parent"
android:layout_height="1dp"
android:background="@android:color/darker_gray"/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/editTextStory"
android:hint="Story"
/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/editTextYearRecorded"
android:hint="Year Recorded"
android:inputType="date"
/>
</LinearLayout>