Reputation: 297
I want to make an edit text in fragment of my view pager(slider). Here what i have done already in my 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;
}
and in 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>
And i cant still see any of edittext field in that view. What am i doing wrong?
I changed it in that way and it works, thanks for help:
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;
Upvotes: 0
Views: 2358
Reputation: 1204
Your Edit Text is there but you just set transparent background so you can't see it.
android:background="#00000000"
you have 4 pairs of zeroes so the format is AARRGGBB the first AA - zeroes in your case - sets the alpha = 0
so the background is fully transparent.
try to set background to #RR0000 or just use RRGGBB format (#000000)
EDIT since above didn't resolve the problem try to update the way you inflate your layout
public View onCreateView(LayoutInflater inflater, ViewGroup parent,
Bundle savedInstanceState) {
aView = inflater.inflate(R.layout.details2, parent, false);
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;
}
the following two lines are the most important:
public View onCreateView(LayoutInflater inflater, ViewGroup parent,
Bundle savedInstanceState) {
and
aView = inflater.inflate(R.layout.details2, parent, false);
Upvotes: 1