Añadir un botón en PrefrenceScreen: Android
Hola, quiero agregar un botón en la pantalla de prefrences, tengo éxito en agregar un botón en la prioridad pero no puedo obtener el evento onClick. He adjuntado mi código una foto de la pantalla de preferencia.
setting.xml
<code><PreferenceCategory android:title="Application Details"> <Preference android:key="type" android:title="Type" android:summary="" /> </PreferenceCategory> <PreferenceCategory android:title="Notification Settings"> <ListPreference android:key="sendNotificationType" android:title="Status Notification For" android:dialogTitle="Status Notification For" /> </PreferenceCategory> </code>
settingdetail.xml
<code><TextView android:id="@+id/textView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentLeft="true" android:layout_alignParentTop="true" android:layout_alignRight="@+id/textView2" android:layout_marginLeft="15dp" android:text="Type" android:textAppearance="?android:attr/textAppearanceLarge" /> <TextView android:id="@+id/textView2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentLeft="true" android:layout_below="@+id/textView1" android:layout_marginLeft="15dp" android:layout_toLeftOf="@+id/setFromTimeBtn" android:text="Summary" android:textAppearance="?android:attr/textAppearanceSmall" /> <Button android:id="@+id/buyItNowBtn" android:layout_width="80dp" android:layout_height="30dp" android:layout_alignParentRight="true" android:layout_marginRight="15dp" android:layout_centerVertical="true" android:background="@drawable/button" android:text="@string/buyItNowBtnTxt" android:textColor="@color/white" /> </code>
y el método onCreate de la clase prefenceActivity
<code>protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); addPreferencesFromResource(R.layout.setting); setContentView(R.layout.settingview); Preference typePref = (Preference) findPreference("type"); typePref.setLayoutResource(R.layout.settingdetail); typePref.setSelectable(true); Button btn = (Button) findViewById(R.id.buyItNowBtn); btn.setOnClickListener(new OnClickListener() { public void onClick(View arg0) { // TODO Auto-generated method stub Log.e(TAG,"TEST"); Toast.makeText(Setting.this, "TEST", Toast.LENGTH_SHORT).show(); } }); } </code>
captura de pantalla