working with preferences.. help needed urgently

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

working with preferences.. help needed urgently

Postby ksp » Wed Nov 19, 2008 2:29 pm

Hi,

I have added a button to a layout which i have set to a preference.

Can anyone let me know how to get a reference to this button to add extra functionality to it?

I tried by using findViewById() method, but i am getting a Null pointer exception when i try to access it.

Hoping for a quick response. Thanks in advance.
ksp
Junior Developer
Junior Developer
 
Posts: 22
Joined: Thu Feb 28, 2008 12:50 pm

Top

Postby ksp » Thu Nov 20, 2008 5:46 am

Can anyone help me out with this???
ksp
Junior Developer
Junior Developer
 
Posts: 22
Joined: Thu Feb 28, 2008 12:50 pm

Postby MrSnowflake » Thu Nov 20, 2008 12:42 pm

I don't get your question...

Did you put the xml as ContentView? otherwise you have to inflate it yourself
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. View inflatedView = View.inflate(R.layout.inflate_me);
  2.  
  3. Button foundButton = (Button)inflatedView.findViewById(R.id.my_button);
Parsed in 0.029 seconds, using GeSHi 1.0.8.4
User avatar
MrSnowflake
Moderator
Moderator
 
Posts: 1439
Joined: Sat Feb 16, 2008 3:11 pm
Location: Flanders, Belgium

Postby feldi13 » Mon May 04, 2009 4:31 pm

Hi,

I have a similar problem like the one described:

I defined an own layout for a Preference item with the android:layout parameter.
With this the new layout is displayed correctly, but i couldnt figure out a way to access the TextView and the Button inside this own layout.

With findViewById() null is returned. With ownPreference.getView().findViewById() I get access to the TextView & Button, but these are not the same as the ones displayed, so its not helpful as well..

Does anybody know a solution for this?
feldi13
Freshman
Freshman
 
Posts: 2
Joined: Mon May 04, 2009 4:10 pm

Postby feldi13 » Wed May 06, 2009 1:14 pm

I found out that I can access the Views defined in the own layout can be accessed in onPreferenceTreeClick() with findViewById() - but not in onCreate(), onStart or onResume() - does anybody know how to access the Views there?

By the way, I'm using SDK 1.1.

Is there any different solution to mix the preferences and their comfortable handling (different existing subclasses like ListPreference, setting title & summary, register for changing values, possibility to define them in an xml file) with own defined views/layouts?
feldi13
Freshman
Freshman
 
Posts: 2
Joined: Mon May 04, 2009 4:10 pm

Top

Return to Other Coding-Problems

Who is online

Users browsing this forum: No registered users and 14 guests