1

Je voudrais fournir un bouton dans le PreferenceActivity. L'utilisateur devrait être en mesure de définir une heure (par exemple via TimePicker), mais il n'y a pas de ButtonPreference ou quelque chose comme ça. Je ne veux pas utiliser EditTextPreference.Android: Comment utiliser les boutons dans l'écran de préférence

Alors est-ce que je dois utiliser un bouton par défaut dans PreferenceActivity et enregistrer les paramètres manuellement?

Cordialement,

cody

Répondre

4

Créer une coutume DialogPreference qui intègre un widget TimePicker. Aucun bouton requis. Devrait être inférieur à 100 lignes de code.

Here is a sample project montrant, entre autres choses, une coutume ColorPreference.

+0

Très bien, merci! :) – cody

0
Create a different layout including your custom controls and include ListView on top, see the example below 

// extra_settings.xml 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       android:orientation="vertical"> 
    <ListView android:id="@android:id/list" 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" android:layout_weight="1"/> 
    <TextView 
      android:id="@+id/feedback" 
      android:text="Feedback" 
      /> 
    <Button 
      android:id="@+id/about" 
      android:text="About" 
      /> 
</LinearLayout> 

Once this done, onCreate method of your class which is extended from PreferenceActivity add following line 

setContentView(R.layout.settings_extras); //name of your layout 


bind OnClickListener 

View.OnClickListener feedbackPageRedirect = new View.OnClickListener() 
     { 
      public void onClick(View v) 
      { 
       Intent emailIntent = new Intent(Intent.ACTION_SEND); 
       emailIntent.putExtra(Intent.EXTRA_SUBJECT, "Feedback "); 

       startActivity(emailIntent); 
      } 
     }; 
0

Vous pouvez placer le bouton dans activity_layout.xml. Par exemple, si "Activity_Setup.java" est votre activité d'installation, "activity_setup.xml" est sa disposition, et "myprefs.xml" est le fichier dans lequel votre disposition de préférence est stockée, puis

vous devriez mettre le bouton dans "activity_setup.xml" dans la liste, le plus préférable dans un TableRow, comme ceci:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent" 
android:layout_height="fill_parent" 
android:orientation="vertical" 
android:id="@+id/llprefs"> 

<ListView 
    android:id="@+id/android:list" 
    android:tag="lvprefs" 
    android:layout_width="match_parent" 
    android:layout_height="0.0dp" 
    android:layout_weight="1" > 
</ListView> 

    <TableRow 
    android:id="@+id/tableRow1" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_marginTop="20dp" 
    > 

    <Button 
     android:id="@+id/btRegister" 
     android:layout_width="wrap_content" 
     android:layout_height="fill_parent" 
     android:layout_weight="1" 
     android:text="@string/IdonothaveA" 
     android:onClick="onClick" 
     /> 

    <Button 
     android:id="@+id/btForgot" 
     android:layout_width="wrap_content" 
     android:layout_height="fill_parent" 
     android:layout_weight="1" 
     android:text="@string/Iforgot" 
     android:onClick="onClick" /> 
    <!-- 
    <Button 
     android:id="@+id/btContact" 
     android:layout_width="wrap_content" 
     android:layout_height="fill_parent" 
     android:layout_weight="1" 
     android:text="@string/Contact" 
     android:onClick="onClick" /> 
    --> 

</TableRow> 

+1

Cette question était assez ancienne - envisager de vérifier certains des plus récents aussi. Bienvenue sur Stack Overflow! – GargantuChet