Reputation: 6778
I have preferences in an Android Live wallpaper app as below. (These are checkboxes). I want to add a link to a Facebook page to this list. Looking at Android PreferenceCategory on the net, I don't see anything like "LinkPreference" or "ButtonPreference", but then again, a link or button isn't really a preference, so maybe I'm trying to fit a square peg in a round hole. Is this possible and if so, how?
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" >
android:title="@string/livewallpaper_settings">
<PreferenceCategory android:title="@string/livewallpaper_settings" >
<CheckBoxPreference
android:defaultValue="true"
android:key="showred"
android:summary="Display red."
android:title="Display red" />
<CheckBoxPreference
android:defaultValue="true"
android:key="showgreen"
android:summary="Display green."
android:title="Display green" />
</PreferenceCategory>
</PreferenceScreen>
This question has been asked before: Android Add Link to a preference activity - how? but not answered.
[Edit] So now have the code below. It does go to Facebook, but only after first clicking on one of the checkbox preferences.
In livewallpaper_settings.xml:
<PreferenceCategory android:title="@string/livewallpaper_settings" >
<Preference
android:key="facebook"
android:summary="@string/facebook"
android:title="@string/facebook" />
</PreferenceCategory>
LiveWallpaperSettings.java:
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key)
{
Log.d("LiveWallpaperSettings.onSharedPreferenceChanged()", "key: " + key);
final Preference mypref = (Preference) findPreference("facebook");
mypref.setOnPreferenceClickListener(new OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(Preference arg0) {
Log.d("LiveWallpaperSettings", "mypref: " + mypref.getKey());
if (mypref.getKey().equals("facebook")) {
Log.d("LiveWallpaperSettings", "LINK TO FACEBOOK");
openWebURL("http://www.facebook.com");
return false;
}
return false;
} });
return;
}
public void openWebURL( String inURL ) {
Log.d("openWebURL", inURL);
Intent browse = new Intent( Intent.ACTION_VIEW , Uri.parse( inURL ) );
startActivity( browse );
}
Upvotes: 1
Views: 1667
Reputation: 1305
How about an EditTextPreference? You can use the same attributes as an EditText
in your EditTextPreference
so you can restrict the input to a single line and display the correct IME for email input etc.
Upvotes: 2