My spinner always takes the same image

2

I'm populating my spinner through an ArrayAdapter but in the past it always shows the same image for all items. Can anyone explain where the error is? Here is my MainActivity

public class MainActivity extends FragmentActivity {
GoogleMap mGoogleMap;

GPSTracker gps;
AlertDialogManager alert = new AlertDialogManager();
Spinner mSprPlaceType;

Button mBtnFind=null;
TextView textview=null;

Place[] mPlaces = null;

String[] mPlaceType=null;

String[] mPlaceTypeName=null;


LatLng mLocation=null;


HashMap<String, Place> mHMReference = new HashMap<String, Place>();

private int arr_images[] = { R.drawable.aeroporto_img,
        R.drawable.pe_img, R.drawable.atm_img,
        R.drawable.banco, R.drawable.autocarros, R.drawable.igreja, 
        R.drawable.hospital, R.drawable.cinema, R.drawable.restaurante,
        R.drawable.escola, R.drawable.museu, R.drawable.cafe, R.drawable.bar };



private static final float UNDEFINED_COLOR = -1;




@Override
protected void onCreate(Bundle savedInstanceState) {        

    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);     

    mPlaceType = getResources().getStringArray(R.array.place_type);


    mPlaceTypeName = getResources().getStringArray(R.array.place_type_name);


    ArrayAdapter<String> adapter = new ArrayAdapter<String> (this, R.layout.mostra_spinner, R.id.mPlaceType, mPlaceTypeName);

    mSprPlaceType = (Spinner) findViewById(R.id.spr_place_type);

    mSprPlaceType.setAdapter(adapter);  

    mBtnFind = ( Button ) findViewById(R.id.btn_find);



    class MyAdapter extends ArrayAdapter<String>{


        public MyAdapter(Context context, int textViewResourceId,   String[] objects) {
            super(context, textViewResourceId, objects);
        }

        @Override
        public View getDropDownView(int position, View convertView,ViewGroup parent) {
            return getCustomView(position, convertView, parent);
        }

        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            return getCustomView(position, convertView, parent);
        }

        public View getCustomView(int position, View convertView, ViewGroup parent) {

            LayoutInflater inflater=getLayoutInflater();
            View row=inflater.inflate(R.layout.mostra_spinner, parent, false);
            TextView label=(TextView)row.findViewById(R.id.mPlaceType); 


            if(position==0){

                // Default selected Spinner item 
                label.setText("Please select company");

            }
            else
            {
                ImageView icon=(ImageView)row.findViewById(R.id.image);
                icon.setImageResource(arr_images[position]);

            }   
            return row;
            }

        }

Here is my activity_main.xml

<Spinner 
            android:id="@+id/spr_place_type"
            android:layout_toRightOf="@+id/image" 
            android:layout_width="240dp"
            android:layout_height="60dp"
            android:layout_alignParentTop="true" 
            android:layout_alignParentLeft="true"
            android:prompt="@string/prompt" />

And my show_descricao.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="3dip"
>
<ImageView

     android:id="@+id/image"
     android:layout_width="wrap_content"
     android:layout_height="wrap_content"
     android:src="@drawable/autocarros"/>
<TextView
     android:layout_toRightOf="@+id/image" 
     android:layout_marginTop="2dip"
     android:textColor="@drawable/black"
     android:textStyle="bold"
     android:id="@+id/mPlaceType"
     android:layout_marginLeft="5dip"
     android:layout_width="wrap_content"
     android:layout_height="wrap_content"
     android:gravity="center"/>

Thanks for the help

    
asked by anonymous 15.09.2015 / 02:01

0 answers