I need to create a drop down which has only three values. I have done this using spinner. But it looks like This
But I am trying to create like This
So while click on this it needs to show the values like normal spinner.
I tried with style and setting selector as background but nothing worked and i thought of custom spinner but did not get anything useful.
Update
activity_main.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="fill_parent"
android:orientation="vertical" >
<Spinner
android:id="@+id/spinner1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:entries="@array/spinner_consigntype"
android:prompt="@string/spinner_consign" />
</LinearLayout>
Activity_Test.Java
package com.mkyong.android;
import android.app.Activity;
import android.os.Bundle;
public class Activity_Test extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_activity__test);
addListenerOnSpinnerItemSelection();
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.activity__test, menu);
return true;
}
public void addListenerOnSpinnerItemSelection(){
Spinner spinner1 = (Spinner) findViewById(R.id.spinner1);
spinner1.setOnItemSelectedListener(new CustomOnItemSelectedListener());
}
}
Listener
public class CustomOnItemSelectedListener implements OnItemSelectedListener {
public void onItemSelected(AdapterView<?> parent, View view, int pos,
long id) {
Toast.makeText(parent.getContext(),
"OnItemSelectedListener : " + parent.getItemAtPosition(pos).toString(),
Toast.LENGTH_SHORT).show();
}
@Override
public void onNothingSelected(AdapterView<?> arg0) {
// TODO Auto-generated method stub
}
}
In my case I am getting the output as like the first image. But with the downloaded code it is showing the output as the second image.