Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8898447
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T00:37:10+00:00 2026-06-15T00:37:10+00:00

I have problem implementing Preference. When i run my app and click on the

  • 0

I have problem implementing Preference.
When i run my app and click on the preference tab nothing happens.
I don’t know what is wrong with the code, Because logcat don’t show anything.
And thanks in advance.

public class Reset extends PreferenceActivity{

private Preference myPreference;

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    myPreference = findPreference("reset");
    myPreference.setOnPreferenceClickListener(new OnPreferenceClickListener() {

        public boolean onPreferenceClick(Preference arg0) {
            Builder alertDialog = new AlertDialog.Builder(Reset.this);
            alertDialog.setMessage("Reset?");
            alertDialog.setCancelable(true);
            alertDialog.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int which) {
                    SharedPreferences settings =  PreferenceManager.getDefaultSharedPreferences(getBaseContext());                          
                    SharedPreferences.Editor editor = settings.edit();
                    editor.clear();
                    editor.commit();
                } }); 
            alertDialog.setNegativeButton("No", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int which) {
                    dialog.cancel();
                } }); 
            alertDialog.show();
            return false;
        }
    });

}

}

XML:

 <?xml version="1.0" encoding="utf-8"?>
 <PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" >
 <Preference android:title="Reset Score" android:key="reset">
 </Preference>
 </PreferenceScreen>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T00:37:11+00:00Added an answer on June 15, 2026 at 12:37 am

    Add this line to your code:

    addPreferencesFromResource(R.xml.preferences);
    

    This code is working:

    import android.app.AlertDialog;
    import android.app.AlertDialog.Builder;
    import android.content.DialogInterface;
    import android.content.SharedPreferences;
    import android.os.Bundle;
    import android.preference.Preference;
    import android.preference.Preference.OnPreferenceClickListener;
    import android.preference.PreferenceActivity;
    import android.preference.PreferenceManager;
    
    public class Reset extends PreferenceActivity{
    
    private Preference myPreference;
    
    @Override
    protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    addPreferencesFromResource(R.xml.preferences);
    myPreference = findPreference("reset");
    myPreference.setOnPreferenceClickListener(new OnPreferenceClickListener() {
        public boolean onPreferenceClick(Preference arg0) {
            Builder alertDialog = new AlertDialog.Builder(Reset.this);
            alertDialog.setMessage("Reset?");
            alertDialog.setCancelable(true);
            alertDialog.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int which) {
                    SharedPreferences settings =   PreferenceManager.getDefaultSharedPreferences(getBaseContext());                          
                    SharedPreferences.Editor editor = settings.edit();
                    editor.clear();
                    editor.commit();
                } }); 
            alertDialog.setNegativeButton("No", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int which) {
                    dialog.cancel();
                } }); 
            alertDialog.show();
            return false;
        }
    });
    
    }
    
    }
    

    And remember to add your activity: Reset to the Manifest:

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm implementing some custom serialization (to byte array), and have run into a problem
I have some problem implementing a segment control. Because i want it to be
We have a strange problem when implementing sessions with ColdFusion in IE6. After login
I have problem while loading data into html select when users press or click
Friends, I'm converting an Oracle Form to Apex and have run into problem(s?) which
Hi I'm having a problem implementing this method. I have added using System.Management but
I have a problem implementing this logic in my project. Im using ServiceLoader and
I am running problems in implementing LIKE in PDO I have this query: $query
I have problem with http://abfoodpolicy.com/ . In IE 8 and 9 the right sidebar
I have problem with my query on C, I’m using the oci8 driver. This

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.