如何获得Android自定义首选项TextView OnClick?

时间:2014-03-10 08:03:20

标签: android xml onclick textview android-preferences

我无法获得自定义偏好TextView操作。我可以知道如何获得它。

这里我的首选项是xml文件user_setting.xml

<PreferenceCategory android:title="@string/security_settings"
        android:key="security">

    <Preference
        android:title="@string/change_pin"
        android:summary="@string/change_pin_summary"
        android:key="change_pin"
        android:layout="@layout/test"/>

</PreferenceCategory>

这是我的自定义xml布局,用于首选项test.xml

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
          android:orientation="vertical"
          android:layout_width="fill_parent"
          android:layout_height="wrap_content"
          android:minHeight="?android:attr/listPreferredItemHeight"
          android:gravity="center_vertical"
          android:paddingLeft="7dp"
          >

<TextView android:id="@android:id/title"
          android:layout_width="fill_parent"
          android:layout_height="wrap_content"
          android:singleLine="true"
          android:ellipsize="marquee"
          android:fadingEdge="horizontal"
          android:textSize="19dp"
        />

<TextView android:id="@android:id/summary"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_below="@android:id/title"
          android:layout_alignLeft="@android:id/title"
          android:textAppearance="?android:attr/textAppearanceSmall"
          android:maxLines="2"
          />

</LinearLayout>

我的活动在这里,

 public class AppPreference extends SherlockPreferenceActivity {

    private boolean needResource=false;

    @SuppressWarnings("deprecation")
    @Override
    public void onCreate(Bundle savedInstanceState){


        super.onCreate(savedInstanceState);

        if (needResource || Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) {
            addPreferencesFromResource(R.xml.user_setting);
        }
        Initialize();

    }

    private void Initialize(){

        Preference change_pin = findPreference("change_pin");
        change_pin.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
            @Override
            public boolean onPreferenceChange(Preference preference, Object newValue) {
                Toast.makeText(getBaseContext(), "PIN",
                        Toast.LENGTH_SHORT).show();
               /* Intent myIntent = new Intent(AppPreference.this, OriginalPinActivity.class);
                AppPreference.this.startActivity(myIntent);*/
                return true;
            }
        });
    }

单击或触摸此首选项时,此功能无效。请指点我怎么做。

0 个答案:

没有答案