2
votes

I have some spinners in my android application. I have loaded data from a remote sql server database via web services. The following is the code for that.

ArrayAdapter<String> reg_adp;
List<String> regions;

reg_adp=new ArrayAdapter<String> (this,android.R.layout.simple_list_item_1,regions);
reg_adp.setDropDownViewResource(android.R.layout.simple_list_item_1);
spinnerMon.setAdapter(reg_adp);

But it shows the retrieved data in big sized letters. And the list coming after clicking the drop down, is also having the text color and the background color same (white).

I want to change the text color and size of that list, and also in the spinner. I tried out creating a new xml file and calling it to the application via ArrayAdaptor like follows. (I got this from another Stack overflow answer)

<?xml version="1.0" encoding="utf-8"?>

<TextView  
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content"
    android:textSize="20dip"
    android:gravity="left"  
    android:textColor="#FF0000"         
    android:padding="5dip"
    />

And code is:

ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, R.layout.spinner_item,list);

The problem coming when I'm going to add the last line. If I add "reg_adp" instead of "list", it gives an error. It requires list as a int. I tried out other various ways. But the same error coming. This may be a very little thing. But I can't find the correct way. Any help would be appriciated.

2

2 Answers

1
votes

Within XML code (spinner_item.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="wrap_content"
android:orientation="horizontal" >

<TextView
    android:id="@+id/textview"
    android:layout_width="wrap_content"
    android:layout_height="50dip"
    android:layout_gravity="center_vertical"
    android:paddingLeft="5dp"
    android:paddingTop="12dp"
    android:textColor="#000000"
    android:textSize="16sp" />

</LinearLayout>

Within java code....

reg_adp=new ArrayAdapter<String> (this,android.R.layout.simple_list_item_1,regions);
        reg_adp.setDropDownViewResource(android.R.layout.simple_list_item_1);

        ArrayList<String> a = new ArrayList<String>();

        for (int i = 0; i < reg_adp.getCount(); i++) {

            a.add(reg_adp.getItem(i));
        }

        ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
                R.layout.spinner_item, R.id.textview, a);
        spinnerMon.setAdapter(adapter);

I just converted String type ArrayAdapter to String type ArrayList.

0
votes

Have you tried changing it from the code, instead setting it up in XML ?