我想在我的视图寻呼机(滑块)的片段中编辑文本。这是我在 DetailFragment2.java 中已经完成的操作:
public View onCreateView(LayoutInflater inflater,
Bundle savedInstanceState) {
LayoutInflater inflater2 = getActivity().getLayoutInflater();
aView = inflater2.inflate(R.layout.details2, null);
EditText notatki = (EditText) aView.findViewById(R.id.editText1);
//notatki = (EditText) getView().findViewById(R.id.editText1);
SharedPreferences settings = this.getActivity().getSharedPreferences("PREFS", 0);
notatki.setText(settings.getString("value", "raz dwa trzy"));
return notatki;
}
并在 details2.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"
>
<EditText
android:id="@+id/editText1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:background="#00000000"
android:ems="10"
android:inputType="textMultiLine" >
<requestFocus />
</EditText>
</RelativeLayout>
而且我仍然无法在该视图中看到任何 edittext 字段。我究竟做错了什么?
我以这种方式对其进行了更改,并且可以正常工作,感谢您的帮助:
View view = inflater.inflate(R.layout.details2, container, false);
EditText notatki = (EditText) view.findViewById(R.id.editText1);
SharedPreferences settings = this.getActivity().getSharedPreferences("PREFS", 0);
notatki.setText(settings.getString("value", "raz dwa trzy"));
return view;