Skip to main content

ANDROID - Set Gujarati font inside Spinner

package com.example.main.util;

import android.app.Activity;
import android.graphics.Typeface;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Spinner;
import android.widget.TextView;

import com.example.testapp.R;

public class testActivity extends Activity {

    private static final String[] COUNTRIES = new String[] { "Belgium",
            "France", "Italy", "Germany", "Spain" };
    private Spinner mySpinner;
    private Typeface myFont;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        setContentView(R.layout.newlay);

        mySpinner = (Spinner) findViewById(R.id.spinner1);
        myFont = Typeface.createFromAsset(getAssets(), "gujarti.ttf");
        MyArrayAdapter ma = new MyArrayAdapter(this);
        mySpinner.setAdapter(ma);
    }

    private class MyArrayAdapter extends BaseAdapter {

        private LayoutInflater mInflater;

        public MyArrayAdapter(testActivity con) {
            // TODO Auto-generated constructor stub
            mInflater = LayoutInflater.from(con);
        }

        @Override
        public int getCount() {
            // TODO Auto-generated method stub
            return COUNTRIES.length;
        }

        @Override
        public Object getItem(int position) {
            // TODO Auto-generated method stub
            return position;
        }

        @Override
        public long getItemId(int position) {
            // TODO Auto-generated method stub
            return position;
        }

        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            // TODO Auto-generated method stub
            final ListContent holder;
            View v = convertView;
            if (v == null) {
                v = mInflater.inflate(R.layout.my_spinner_style, null);
                holder = new ListContent();

                holder.name = (TextView) v.findViewById(R.id.textView1);

                v.setTag(holder);
            } else {

                holder = (ListContent) v.getTag();
            }

            holder.name.setTypeface(myFont);
            holder.name.setText("" + COUNTRIES[position]);

            return v;
        }

    }

    static class ListContent {

        TextView name;

    }
}

in layout:

 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"  
   android:layout_width="fill_parent"  
   android:layout_height="fill_parent"  
   android:orientation="vertical" >  
   <Spinner  
     android:id="@+id/spinner1"  
     android:layout_width="match_parent"  
     android:layout_height="wrap_content" />  
 </LinearLayout>  

my_spinner_style.xml

 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"  
   android:layout_width="fill_parent"  
   android:layout_height="fill_parent" >  
   <TextView  
     android:id="@+id/textView1"  
     android:layout_width="match_parent"  
     android:layout_height="wrap_content"  
     android:text="Large Text"  
     android:textAppearance="?android:attr/textAppearanceLarge" />  
 </LinearLayout>  

This is asked on stackoverflow.

Comments

Popular posts from this blog

Android - Google MAP V2 PART 1

Download Full Code  of PART-1 , 2 , 3 , 4 Download and configure Google Play Services Library in Eclipse Google Map for Android is now integrated with Google Play Services. So we need to set up Google Play Service Library for developing Google Map application in Android. Get the API key for Google Maps v2: Linux  :  For any other OS use this :  keytool -list -v -alias androiddebugkey \ -keystore <path_to_debug_keystore>debug.keystore \ -storepass android -keypass android Register with the Google APIs Console :    Google APIs Console  Select here the  Services  entry: Activate the  Google Maps Android API v2 . Register your application via its package in this console together with the SHA-1 fingerprint of your signature key. Click on Create new Android Key.. Add you SHA-1 and your package name in to box like example given in alert box. Support library...

Share Text To Facebook & Twitter ANDROID

Shaadi.com Indian Matrimonials Before Create this app you must Have to create Application on FACEBOOK & TWITTER Download Code

Android - Google MAP V2 PART 2

Download Full Code  of  PART-1 , 2 , 3 , 4 Before do this check part 1 Note : I have to run this in API 8 to API 17 that why i have used  ActionBarSherlock  support library. if you don't want that then replace it.  In main Activity i have added following code. package com.djandroid.mapsv2; import android.os.Bundle; import android.support.v4.app.FragmentManager; import com.actionbarsherlock.app.SherlockFragmentActivity; import com.google.android.gms.maps.GoogleMap; import com.google.android.gms.maps.GoogleMap.OnMapClickListener; import com.google.android.gms.maps.SupportMapFragment; import com.google.android.gms.maps.model.LatLng; import com.google.android.gms.maps.model.MarkerOptions; public class MainActivity extends SherlockFragmentActivity { private GoogleMap MAP; @Override protected void onCreate(Bundle arg0) { // TODO Auto-generated method stub setTheme(R.style....