Skip to main content

Android: Custom PreferenceScreen

1) preferences_holder.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
   android:layout_width="fill_parent" 
   android:layout_height="fill_parent"
   android:orientation="vertical">
   <LinearLayout 
          android:orientation="horizontal" 
       android:background="@color/bto_dark_green" 
       android:layout_width="fill_parent"
       android:gravity="center_vertical" 
       android:layout_height="wrap_content"
       android:paddingTop="4dip">
     <Button
        android:id="@+id/backPrefBurron" 
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" 
        android:text="Home" />
     <TextView 
        android:id="@+id/backText" 
        android:textSize="14dip"
        android:paddingLeft="5dip" 
        android:textColor="@color/white"
        android:textStyle="bold"  
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"  
        android:layout_weight="1.0"
        android:text="Preferences: Home will update all areas of the app" />
  </LinearLayout>
  <ListView 
        android:id="@android:id/list" 
        android:layout_width="fill_parent"
        android:layout_height="fill_parent" />
</LinearLayout>
2) preferences.xml
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
    android:background="@color/bto_light_green">

<EditTextPreference  
    android:title="Your BTO UserName"
    android:key="username"  
    android:summary="Please provide your username">
</EditTextPreference>
<EditTextPreference  
    android:title="Your BTO Password"
    android:password="true" 
    android:key="password" 
    android:summary="Please provide your password (case sensitive)">
</EditTextPreference>
<ListPreference  
    android:title="Species order"
    android:summary="This preference selects the species order 
                for some viewing sightings activities"
    android:key="speciesorder" 
    android:defaultValue="date_order" 
    android:entries="@array/listArray"
    android:entryValues="@array/listValues">
</ListPreference>
</PreferenceScreen> 
3) Preferences.java 
import android.content.Intent;
import android.os.Bundle;
import android.preference.PreferenceActivity;
import android.view.View;
import android.widget.Button;

public class Preferences extends PreferenceActivity {
   @Override
   protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.preference_holder);
    addPreferencesFromResource(R.layout.preferences);

    Button backButton = (Button) findViewById(R.id.backPrefBurron);
    backButton.setOnClickListener(new View.OnClickListener() {
        public void onClick(View view) {
            Intent myIntent = new Intent(getBaseContext(),
                    BTFirstTab.class);
            startActivity(myIntent);
        }
    });

     }
}  


Comments

Popular posts from this blog

Error: Retrieving parent for item: No resource found that matches the given name after upgrading to AppCompat v23

My project is going on easily but suddenly what I found below bugs when developing an app. I know it's minor bug but it may be useful to anyone. Here is the error: Error:(2) Error retrieving parent for item: No resource found that matches the given name 'android:TextAppearance.Material.Widget.Button.Inverse'. Error:(2) Error retrieving parent for item: No resource found that matches the given name 'android:Widget.Material.Button.Colored'. Solution: This happens because after updates your android studio uses API 23 by default. 1) First check that your compile SDK version must match the support library's major version. If you are using version 23 of the support library, you need to compile against version 23 of the Android SDK. Alternatively you can continue compiling against version 22 of the Android SDK by switching to the latest support library v22.   2) Go to your project structure -> Properties -> and change Build tool version to...

Be aware while Posting photo from a native ShareDialog in Facebook android SDK

Add the content provider to your manifest. <provider  android:name="com.facebook.NativeAppCallContentProvider" android:authorities="com.facebook.app.NativeAppCallContentProvider{Facebook-App-Id}" android:exported="true" /> Make sure exported=true (as above) Example: <provider android:name="com.facebook.NativeAppCallContentProvider" android:authorities="com.facebook.app.NativeAppCallContentProvider123456" android:exported="true" />

Youtube API: Service Intent must be explicit

Whe n I am using Youtube API and open the video in my application then it shows me below error in Android L Problem java.lang.IllegalArgumentException: Service Intent must be explicit: Intent { act=com.google.android.youtube.api.service.START } Solution: *  The new android youtube SDK as been released! No more implicit intent problem: https://developers.google.com/youtube/android/player/downloads/