0

I have a EditPreferences.class which extends preferenceactivity and my preferences.xml layout in my xml folder in the xml layout i used EditTextPreference control which have layout et_layout.xml my question is how can i get my textview id in my EditPreferences.class

  <PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
  android:title="@string/app_name" >
  <PreferenceCategory
    android:icon="@drawable/batitle"
    android:textColor="#000000"
    android:title="كۆرۈنۈش" >
    <ListPreference
        android:defaultValue="@string/result_fontsize_default"
        android:dialogTitle="تاللاڭ"
        android:entries="@array/result_fontsize_keys"
        android:entryValues="@array/result_fontsize_values"
        android:key="result_fontsize"
        android:summary="ئىزدەش نەتىجىسىنىڭ كۆرۈنۈش چوڭلۇقى"
        android:textColor="#000000"
        android:title="خەت چوڭلۇقى" />

    <EditTextPreference
        android:dialogIcon="@drawable/batitle"
        android:dialogTitle="editText"
        android:key="tel"
        android:layout="@layout/layout" />

    <Preference />
   </PreferenceCategory>

   </PreferenceScreen>

layout

  <?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"
android:gravity="right"
android:orientation="horizontal" >

<LinearLayout
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <TextView
        android:id="@+id/textView2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="TextView" />

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="TextView" />

</LinearLayout>

<ImageView
    android:id="@+id/imageView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:src="@drawable/ic_launcher" />

 </LinearLayout>
RealDream
  • 407
  • 3
  • 6
  • 18

3 Answers3

0

Inflate you xml

    LayoutInflater inflater = LayoutInflater.from(this);
    View view = inflater.inflate(R.layout.linear_layout, null);

    textView2 = (TextView) view.findViewById(R.id.textView2);

Try this, hope it would help you out

Namrata
  • 1,683
  • 1
  • 17
  • 28
0

Try this,

SharedPreferences prefs;
String x = prefs.getString("tel",defaultString value);
textView.setText(x);
Mayuri Ruparel
  • 694
  • 2
  • 11
  • 36
0

The reason why a simple findViewById in your EditPreferences.onCreate doesn't work is because your layout with the TextView is created inside of a ListView and there is a delay before that actually happens when the activity is launched.

I'm not sure this is the best way, but one way to handle the event of ListView item population is to handle the OnHierarchyChange event for the ListView object. If you put this in your onCreate, after the preference layout has been loaded from what I assume is a call to addPreferencesFromResource, it should work.

ListView list = (ListView) findViewById(android.R.id.list);
list.setOnHierarchyChangeListener(new ViewGroup.OnHierarchyChangeListener() {
    @Override
    public void onChildViewAdded(View parent, View child) {
        TextView text = (TextView) child.findViewById(R.id.textView2);
        if (text != null) {
            text.setText("Something else here");
        }
    }

    @Override
    public void onChildViewRemoved(View view, View view2) {
    }
});
mikeplate
  • 1,149
  • 8
  • 10