Custom Preference

Preference is setting page for Android.
Android provides several Preference type for setting.

But, sometimes we need special custom setting.
In that case, we can extend Preference class and use it as preference.

Example

Open Web page Preference

public class WebPreference extends Preference
{
	private String url = "http://atmarkplant.com";
	
	public WebPreference(Context context, AttributeSet attrs) 
	{
		super(context, attrs);
	}

	@Override
	protected void onClick ( )
	{
		Uri uri = Uri.parse(url);
		Intent intent = new Intent(Intent.ACTION_VIEW, uri);
		getContext().startActivity(intent);
	}
}

The main method is onClick.

How to use?
It is just as same other Preference(.xml)

<PreferenceCategory android:title="@string/web">
   <com.atmarkplant.prefs.WebPreference
    android:title="@string/websummary"
    android:summary="@string/websummary"/>
</PreferenceCategory>