Hmm...I am suffering with same problem.
why getView() returns unrelated view..
So..did you find any solution?
please refer below sample code.
preference_layout.xml
<LinearLayout
...
<CheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/pref_cb"
android:onClick="onClickCheckBox"
android:layout_gravity="center_vertical"/>
/>LinerLayout
/xml/main.xml
...
<Preference
android:key="pref_key"
android:title="preference test"
android:layout="@layout/preference_layout"/>
PreferenceActivity.java
....
public void onClickCheckBox(View view) {
if(view != null) {
cb = (CheckBox) view.findViewById(R.id.pref_cb);
if(cb != null) {
Log.e("Activity", "Wow");
}
Log.e("Activity", "Check state:" + cb.isChecked());
}
}
Absolutely, onClickCheckBox() methos run when I click check box.
But, still I can't find the way how can get the root view of
LinearLayout.
If someone can have the solution that will be very useful tip.
Because we don't need to implement custom preference java source file
any more.
Have good weekend~~~~
On 3월11일, 오전4시28분, jotobjects <[email protected]> wrote:
> Did you try this
>
> RadioGroup rg = (RadioGroup)findViewById(R.id.radio_group_prefs);
>
> On Mar 1, 6:47 pm, mjk <[email protected]> wrote:
>
>
>
> > So... turns out I was lying horribly. ;P The line that instantiates
> > prefView reads as such:
>
> > RadioGroup prefView = (RadioGroup) sharingPrefs.getView(new
> > RadioGroup(this), null);
>
> > So it looks like I was getting a new, completely unrelated
> > RadioGroup. Does anyone know how I can get access to the actual
> > RadioGroup that's being rendered?
>
> > Thanks,
> > Myung
>
> > On Mar 1, 4:52 pm, mjk <[email protected]> wrote:
>
> > > Hello all,
>
> > > I'm trying to make a somewhat advanced settings Activity (one that has
> > > a RadioGroup in one of the cells). The layout xml file contains the
> > > following:
>
> > > <?xml version="1.0" encoding="utf-8"?>
>
> > > <PreferenceScreen
> > > xmlns:android="http://schemas.android.com/apk/res/android"
>
> > > <PreferenceCategory android:title="Email">
>
> > > <EditTextPreference
> > > android:name="changeEmail"
> > > android:summary="Click to Change Email"
> > > android:persistent ="false"
> > > android:title="Click to Change Email"
> > > android:key="editTextPref" />
> > > </PreferenceCategory>
>
> > > <PreferenceCategory android:title="Location Sharing">
> > > <Preference
> > > android:title="placeholder"
> > > android:summary="summary text"
> > > android:layout_width="fill_parent"
> > > android:layout_height="wrap_content"
> > > android:key="sharingPrefs"
> > > android:layout="@+id/radio_group_prefs"
> > > />
>
> > > </PreferenceCategory>
> > > ...
>
> > > Another layout xml file (radio_group_preferences.xml) contains the
> > > following:
>
> > > <?xml version="1.0" encoding="utf-8"?>
> > > <RadioGroup
> > > xmlns:android="http://schemas.android.com/apk/res/android"
> > > android:id="@+id/radio_group_prefs"
> > > android:layout_width="fill_parent"
> > > android:layout_height="wrap_content"
> > > android:orientation="vertical">
>
> > > <RadioButton
> > > android:checked="false"
> > > id="@+id/option1"
> > > android:text="radio_group_1_option1"
> > > />
>
> > > <RadioButton
> > > android:checked="false"
> > > android:text="radio_group_1_option2"
> > > id="@+id/option2" />
>
> > > <RadioButton
> > > android:checked="false"
> > > android:text="radio_group_1_option3"
> > > id="@+id/option3" />
>
> > > </RadioGroup>
>
> > > In my settings activity java class, I have the following:
>
> > > protected void onCreate(Bundle savedInstanceState) {
> > > super.onCreate(savedInstanceState);
> > > addPreferencesFromResource(R.layout.settings);
>
> > > //email textfield setup omitted
>
> > > Preference sharingPrefs =
> > > (Preference)findPreference("sharingPrefs");
> > > RadioGroup prefView = (RadioGroup)
> > > sharingPrefs.getView(null,
> > > null);
> > > prefView.setOnCheckedChangeListener(radioListener);
>
> > > }
>
> > > And the RadioGroup listener is defined as such:
>
> > > RadioGroup.OnCheckedChangeListener radioListener = new
> > > OnCheckedChangeListener() {
>
> > > @Override
> > > public void onCheckedChanged(RadioGroup group, int
> > > checkedId) {
> > > Log.v(TAG, "Radio check changed, checkedId =
> > > "+checkedId);
> > > }
> > > };
>
> > > Now here's the weird part. It runs and renders correctly. However,
> > > when I shift around the radio button, I don't get the log messages.
> > > Going through the debugger, I could see that the RadioGroup's
> > > onCheckedChangedListener was getting set correctly (at least, it was
> > > null before the call to setOnCheckedChangeListener and it wasn't null
> > > afterward). How can this be? It seems like the calls to
> > > onCheckedChanged are somehow being suppressed. Is this a legitimate
> > > bug?
>
> > > Thanks,
> > > Myung- 원본 텍스트 숨기기 -
>
> - 원본 텍스트 보기 -
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
To unsubscribe from this group, send email to
android-developers+unsubscribegooglegroups.com or reply to this email with the
words "REMOVE ME" as the subject.