Note that there are some explanatory texts on larger screens.

plurals
  1. POAdd a Button into PrefrenceScreen : Android
    primarykey
    data
    text
    <p>Hi i want to add a button into prefrencescreen, i got success into add a button into the prefrence but i could not get onClick event. i have attached my code a pic of prefence screen</p> <p>setting.xml </p> <pre><code>&lt;PreferenceCategory android:title="Application Details"&gt; &lt;Preference android:key="type" android:title="Type" android:summary="" /&gt; &lt;/PreferenceCategory&gt; &lt;PreferenceCategory android:title="Notification Settings"&gt; &lt;ListPreference android:key="sendNotificationType" android:title="Status Notification For" android:dialogTitle="Status Notification For" /&gt; &lt;/PreferenceCategory&gt; </code></pre> <p></p> <p>settingdetail.xml</p> <p> </p> <pre><code>&lt;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" /&gt; &lt;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" /&gt; &lt;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" /&gt; </code></pre> <p></p> <p>and the onCreate Method of prefenceActivity Class</p> <pre><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></pre> <p><strong>screenshot</strong></p> <p><img src="https://i.stack.imgur.com/agdUy.png" alt="enter image description here"></p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload