Spinner original text

Posted by user1696863 on Stack Overflow See other posts from Stack Overflow or by user1696863
Published on 2012-10-09T07:36:36Z Indexed on 2012/10/09 9:37 UTC
Read the original article Hit count: 211

Filed under:
|

I'm trying my Spinner to display "Select City" before the Spinner has itself been clicked by the user.

How can I do this?

My current XML code is:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:custom="http://schemas.android.com/apk/res/com.olacabs.customer"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@drawable/page_background"
    android:orientation="vertical" >

 <TextView
    android:id="@+id/textView1"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:background="@android:color/darker_gray"
    android:gravity="center"
    android:paddingBottom="4dp"
    android:paddingTop="4dp"
    android:text="@string/rate_card"
    android:textColor="@color/white"
    android:textSize="20dp"
    custom:customFont="litera_bold.ttf" />

 <Spinner
    android:id="@+id/select_city"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_marginTop="40dp"
    android:prompt="@string/selectCity" />

</LinearLayout>

Also, what does android:spinnerMode exactly do. I tried changing its value to dropdown but nothing happened and the application still showed a popup dialogue.

My activity that implements this XML file is:

public class RateCardActivity extends OlaActivity {

    public void onCreate(Bundle bundle) {
        super.onCreate(bundle);
        setContentView(R.layout.rate_card);

        Spinner spinner = (Spinner) findViewById(R.id.select_city);
        ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this,
        R.array.select_city, android.R.layout.simple_spinner_item); 
        adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        spinner.setAdapter(adapter);
    }
}

© Stack Overflow or respective owner

Related posts about android

Related posts about android-spinner