Simple preferences

Put your problem here if it does not fit any of the other categories.

Simple preferences

Postby ajent » Fri Jun 25, 2010 11:43 pm

I'm using eclipse, and the tutorials i'm seeing online are conflicting with how I set up the menu & preferences I believe.

My app has 2 tabs, tab 0 is default shown. When you click menu, then preferences, the 2 options are displayed correctly, but nothing happens when you press either one, because I don't know how to properly code it.

When the "uso" preference is clicked, I want tab 0 to be default tab. When "ush" is clicked, I want tab 1 to be the default.

Thanks
ajent
Junior Developer
Junior Developer
 
Posts: 12
Joined: Fri Jun 04, 2010 3:55 am

Top

Re: Simple preferences

Postby nicholas.hauschild » Sat Jun 26, 2010 4:07 am

Are you using the preferences framework, or a custom preference setup??
nicholas.hauschild
Master Developer
Master Developer
 
Posts: 310
Joined: Fri Dec 04, 2009 4:50 am

Re: Simple preferences

Postby ajent » Sat Jun 26, 2010 5:21 pm

I used eclipse to make a new "android xml" file then chose menu for the first one, which created the menu.xml then did it again and selected preference which created the preferences.xml file

I can post the contents of those 2 files if that will help
ajent
Junior Developer
Junior Developer
 
Posts: 12
Joined: Fri Jun 04, 2010 3:55 am

Re: Simple preferences

Postby nicholas.hauschild » Sat Jun 26, 2010 5:43 pm

please do
nicholas.hauschild
Master Developer
Master Developer
 
Posts: 310
Joined: Fri Dec 04, 2009 4:50 am

Re: Simple preferences

Postby ajent » Sat Jun 26, 2010 9:34 pm

I can probably figure out the code to display the proper tab, I just need to know the basic.
I found this code: http://stackoverflow.com/questions/3085 ... preference which I think would help me, but i'm not sure where to put it, as when I inserted it to the main class, it gave me errors.

*Code updated in next post*

I appreciate your help with this, it's hard to get replies as i'm still very new to this, and it is much different than visual studio.
ajent
Junior Developer
Junior Developer
 
Posts: 12
Joined: Fri Jun 04, 2010 3:55 am

Re: Simple preferences

Postby ajent » Tue Jun 29, 2010 3:58 am

I spent a few hours screwing around, and put the correct code in the place it should be (I believe), since I did a test with the preference click and it correctly displayed a toast message.
Now here is the contents of the Preferences class as I think it would work correctly:
Preferences.java
Code: Select all
package com.fbisoft.uowt;

import android.os.Bundle;
import android.preference.Preference;
import android.preference.PreferenceActivity;
import android.preference.Preference.OnPreferenceClickListener;
import android.widget.Toast;



public class Preferences extends PreferenceActivity {

   /** Called when the activity is first created. */
   
   @Override
   public void onCreate(Bundle savedInstanceState) {
       super.onCreate(savedInstanceState);
       addPreferencesFromResource(R.xml.preferences);
      
            getPreferenceManager().findPreference("uso").setOnPreferenceClickListener(new OnPreferenceClickListener()
        {
            @Override
            public boolean onPreferenceClick(Preference preference)
            {
               TabHost.setCurrentTab(1);
               
               return true;
            }
        });
   }
   
   

}


The problem now is TabHost.setCurrentTab(1); gives the error "Cannot make a static reference to the non-static method setCurrentTab(int)"

What i'm trying to do is set the current tab that is viewed to tab 1, instead of tab 0.
ajent
Junior Developer
Junior Developer
 
Posts: 12
Joined: Fri Jun 04, 2010 3:55 am

Top

Re: Simple preferences

Postby anarche » Tue Jun 29, 2010 5:33 am

use Activity.getTabHost() to get the tab host.

This is a Java error, not an Android error. If you are new to Java you may wish to try some easier tutorials or Java lessons first.
anarche
Master Developer
Master Developer
 
Posts: 369
Joined: Sun Apr 11, 2010 5:21 am

Top

Return to Other Coding-Problems

Who is online

Users browsing this forum: Google [Bot] and 18 guests