[Solved] Set value for Spinner with custom Adapter in Android

@Haresh Chhelana example is good, However if you want to show both name and code in spinner after selecting, check this out. List<Map<String, String>> items = new ArrayList<Map<String, String>>(); for (int i = 0; i < JA.length(); i++) { json = JA.getJSONObject(i); mapData = new HashMap<String, String>(); mapData.put(“name”, json.getString(“Name”)); mapData.put(“code”, json.getString(“Code”)); items.add(mapData); } SimpleAdapter adapter … Read more

[Solved] Android Spinner showing transparent screen with distortion of data,but items are selectable

Add this dependencies in build.gradle file compile ‘com.github.rey5137:material:1.2.2’ In Xml write this code. <com.rey.material.widget.Spinner android:id=”@+id/spinner_label” style=”@style/LightSpinner” android:layout_width=”match_parent” android:layout_height=”wrap_content” android:gravity=”center” android:minWidth=”128dp” android:padding=”8dp” app:spn_label=”Spinner with arrow” /> In Java class write this code. Spinner spn_label = (Spinner) findViewById(R.id.spinner_label); String[] items = new String[20]; for (int i = 0; i < items.length; i++) { items[i] = “Item ” … Read more

[Solved] get the selected value position

Try this way,hope this will help you to solve you problem. main.xml <LinearLayout xmlns:android=”http://schemas.android.com/apk/res/android” android:layout_width=”match_parent” android:layout_height=”match_parent” android:orientation=”vertical” android:gravity=”center”> <Button android:id=”@+id/btnSelectGender” android:layout_width=”wrap_content” android:layout_height=”wrap_content” android:text=”Select Gender”/> </LinearLayout> MyActivity.java public class MyActivity extends Activity { private Button btnSelectGender; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); btnSelectGender = (Button) findViewById(R.id.btnSelectGender); btnSelectGender.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) … Read more

[Solved] How can I showing checkbox when I choose the spinner data?

try this custom Class public class MultiSelectionSpinner extends Spinner implements OnMultiChoiceClickListener { String[] _items = null; boolean[] mSelection = null; boolean[] mSelectionAtStart = null; String _itemsAtStart = null; ArrayAdapter<String> simple_adapter; public MultiSelectionSpinner(Context context) { super(context); simple_adapter = new ArrayAdapter<>(context, android.R.layout.simple_spinner_item); super.setAdapter(simple_adapter); } public MultiSelectionSpinner(Context context, AttributeSet attrs) { super(context, attrs); simple_adapter = new ArrayAdapter<>(context, android.R.layout.simple_spinner_item); … Read more

[Solved] Trying to add an onItemSelectedListener to a spinner

Here is how spinner can be used // Reference the spinner Spinner spinner = (Spinner) findViewById(R.id.spinner); // Set spinner onItemClickListener spinner.setOnItemSelectedListener(new OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2, long arg3) { Toast.makeText(secActivity.this, “You have clicked”, Toast.LENGTH_SHORT).show(); } }); 2 solved Trying to add an onItemSelectedListener to a spinner