Android Beautiful Spinner view without Custom adapter

To make this just bind spinner with cardview . and make it like the code bellow . now it will looks beautiful .

 

<android.support.v7.widget.CardView
    android:layout_width="match_parent"
    android:layout_height="@dimen/count_40dp"
    android:layout_marginLeft="@dimen/count_5dp"
    android:layout_marginRight="@dimen/count_5dp"
    android:layout_marginTop="@dimen/count_10dp">

    <Spinner
        android:id="@+id/gender"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />
</android.support.v7.widget.CardView>

Android Custom spinner .

Step -1 : Create new Adapter .

public class CustomSpinnerAdapter extends BaseAdapter implements SpinnerAdapter {
 
        private final Context context;
        private ArrayList<String> asr;
 
        public CustomSpinnerAdapter(Context context1, ArrayList<String> asr) {
            this.context = context1;
            this.asr=asr;

        }
 
 
 
        public int getCount()
        {
            return asr.size();
        }
 
        public Object getItem(int i)
        {
            return asr.get(i);
        }
 
        public long getItemId(int i)
        {
            return (long)i;
        }
 
 
 
        @Override
        public View getDropDownView(int position, View convertView, ViewGroup parent) {
            TextView txt = new TextView(context);
            txt.setPadding(16, 16, 16, 16);
            txt.setTextSize(18);
            txt.setGravity(Gravity.CENTER_VERTICAL);
            txt.setText(asr.get(position));
            txt.setTextColor(Color.parseColor("#000000"));
            return  txt;
        }
 
        public View getView(int i, View view, ViewGroup viewgroup) {
            TextView txt = new TextView(context);
            txt.setGravity(Gravity.CENTER);
            txt.setPadding(16, 16, 16, 16);
            txt.setTextSize(16);
            txt.setCompoundDrawablesWithIntrinsicBounds(0, 0, R.drawable.ic_down, 0);
            txt.setText(asr.get(i));
            txt.setTextColor(Color.parseColor("#000000"));
            return  txt;
        }
 
    }

2. Create new drawable

<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle"
    >
    <solid android:color="@android:color/white"/>


    <corners android:radius="4dp"></corners>
<stroke android:color="#cccccc" android:width="1dp"/>

</shape>

3. Create spinnerview in xml layout .

<android.support.v7.widget.CardView
    android:layout_width="match_parent"
    android:layout_height="@dimen/count_40dp"
    android:layout_marginLeft="@dimen/count_5dp"
    android:layout_marginRight="@dimen/count_5dp"
    android:layout_marginTop="@dimen/count_10dp">

    <Spinner
        android:id="@+id/gender"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />
</android.support.v7.widget.CardView>

4 . Call the custom Spinner in Activity

 ArrayList<String> languages = new ArrayList<String>();
    languages.add("Male");
    languages.add("Female");
    // Creating adapter for spinner
    ArrayAdapter<String> dataAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, languages);

   CustomSpinnerAdapter customSpinnerAdapter=new CustomSpinnerAdapter(mContext,languages);
   genderSpinner.setAdapter(dataAdapter );
    genderSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {

            String item = parent.getItemAtPosition(position).toString();

            genderString = item;
        }

        @Override
        public void onNothingSelected(AdapterView<?> parent) {

        }
    });
}

5 . Run it . That’s all .

Error:Execution failed for task ‘:app:processDebugManifest’. > Manifest merger failed

Problem :

Error:Execution failed for task ‘:app:processDebugManifest’. > Manifest merger failed : Attribute meta-data#com.facebook.sdk.ApplicationId@value value=(@string/facebook_app_id) from AndroidManifest.xml:36:13-52 is also present at [com.firebaseui:firebase-ui-auth:3.1.0] AndroidManifest.xml:21:13-60 value=(@string/facebook_application_id). Suggestion: add ‘tools:replace=”android:value”‘ to <meta-data> element at AndroidManifest.xml:34:9-36:55 to override.

Solution :

 

<meta-data
    android:name="com.facebook.sdk.ApplicationId"
    android:value="@string/facebook_app_id"
    tools:replace="android:value"/>

Firebase: A config file was found, but it indicates a project ID “priokotha-92c0e” that you dont appear to have access to. Request access or delete the file in order to proceed with the connection process.

This error will occur if you are signed in to Android Studio and the Firebase Console with different accounts.

In Android Studio, click on the small profile icon in the upper right corner to see your sign-in account. Do the same for the Firebase Console tab of your browser. If they are different, sign out and sign in to make them the same.

 

 

ERROR:’keytool’ is not recognized as an internal or external command, operable program or batch file

Step 1 :

Download JDK : http://www.oracle.com/technetwork/java/javase/downloads/index.html and install it .

Step 2 :

Set the path on environment path . To do this My Computer – > Properties -> System variable -> Edit Path , click new and past jre bin path location .

Check that the directory the keytool executable is in is on your path. (For example, on my Windows 7 machine, it’s in C:\Program Files (x86)\Java\jre6\bin.)

 

  • keytool path may be different . find the keytool and select the parent directory .

 

Android firebase Phone verification authentication – OTP

Step 1 :

Go to firebase console . Go SIGN-IN METHOD and enable phone authentication option .

 

Step 2 :

Open your build.gradle (app) and paste this firebase ui gradle and sync . Check firebase version code . It may vary .

compile 'com.firebaseui:firebase-ui-auth:3.1.0'
compile 'com.google.android.gms:play-services-auth:11.4.2'

Step 3 :

 private static final int RC_SIGN_IN = 123; 

Step 4 :

Paste this on OnCreate method .

FirebaseAuth auth = FirebaseAuth.getInstance();
if (auth.getCurrentUser() != null) {
AuthUI.EXTRA_DEFAULT_NATIONAL_NUMBER.toString();
// SavedData.user = auth.getCurrentUser().toString();
startActivity(new Intent(context, MainActivity.class));
finish();
} else {
// not signed in
startActivityForResult(
AuthUI.getInstance()
.createSignInIntentBuilder()
.setAvailableProviders(
Arrays.asList(
new AuthUI.IdpConfig.Builder(AuthUI.PHONE_VERIFICATION_PROVIDER).build()
))
.build(),
RC_SIGN_IN);
} 

Step – 4 :

implement this callback method

protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    // RC_SIGN_IN is the request code you passed into startActivityForResult(...) when starting the sign in flow.
    if (requestCode == RC_SIGN_IN) {
        IdpResponse response = IdpResponse.fromResultIntent(data);
        // Successfully signed in
        if (resultCode == ResultCodes.OK) {

            startActivity(new Intent(context, MainActivity.class));
            finish();
            return;
        } else {
            // Sign in failed
            if (response == null) {
                // User pressed back button
                Log.e("Login", "Login canceled by User");
                return;
            }
            if (response.getErrorCode() == ErrorCodes.NO_NETWORK) {
                Log.e("Login", "No Internet Connection");
                return;
            }
            if (response.getErrorCode() == ErrorCodes.UNKNOWN_ERROR) {
                Log.e("Login", "Unknown Error");
                return;
            }
        }
        Log.e("Login", "Unknown sign in response");
    }
}

Error:Execution failed for task ‘:app:transformDexArchiveWithExternalLibsDexMergerForDebug’. > java.lang.RuntimeException: java.lang.RuntimeException: com.android.builder.dexing.DexArchiveMergerException: Unable to merge dex

It may causes for several reasons – I have found 2 reason and solution .

 Problem 1 :

If you use firebase service and it’s gradle version are older version . Or google play service , gms service are not updated version that can create this problem .

Solution :

Update all gradle version updated and same version for firebase .

Problem 2 : 

If multidex not enabled

Solution : 

Android Multi-dex Enable