Добавить кнопку в PrefrenceScreen: Android
Привет, я хочу добавить кнопку в экран настроек, я успешно добавил кнопку в настройку, но не смог получить событие onClick. я прикрепил свой код к картинке с защитным экраном
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>
и метод onCreate класса 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>
screenshot