JAVA
Spinner spinner;
ArrayAdapter<CharSequence> adapter;
//Spinner for No_of_persons
spinner=(Spinner)findViewById(R.id.spinner);
adapter=ArrayAdapter.createFromResource(getApplicationContext(),R.array.person_count,android.R.layout.simple_spinner_item);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
Spinner.setAdapter(adapter);
spinner.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Toast.makeText(getBaseContext(),parent.getItemIdAtPosition(position)+"selected",Toast.LENGTH_LONG).show();
}
});
XML
<RelativeLayout
android:id="@+id/specificationrellay"
android:layout_below="@+id/droplocation"
android:layout_width="match_parent"
android:layout_marginTop="5dp"
android:layout_height="match_parent">
<TextView
android:id="@+id/tvseatingcapacity"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Seating Capacity"
android:textStyle="normal"
android:fontFamily="casual"
android:textSize="18dp"
android:layout_marginLeft="5dp"
/>
<TextView
android:id="@+id/capacity"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="6"
android:textStyle="normal"
android:fontFamily="casual"
android:textSize="20dp"
android:textColor="@color/black"
android:layout_marginTop="2dp"
android:layout_below="@+id/tvseatingcapacity"
android:gravity="center_horizontal"
android:layout_marginLeft="65dp"
/>
<TextView
android:id="@+id/time"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Time"
android:layout_toRightOf="@+id/tvseatingcapacity"
android:textStyle="normal"
android:fontFamily="casual"
android:textSize="18dp"
android:layout_marginLeft="18dp"
android:layout_marginTop="2dp"/>
<TextView
android:id="@+id/realtime"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="10:30 AM"
android:textStyle="normal"
android:fontFamily="casual"
android:textSize="20dp"
android:textColor="@color/black"
android:layout_marginTop="2dp"
android:layout_below="@+id/time"
android:layout_toRightOf="@+id/capacity"
android:gravity="center_horizontal"
android:layout_marginLeft="65dp"
/>
<TextView
android:id="@+id/noofperson"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="No.Of Persons"
android:layout_toRightOf="@+id/time"
android:textStyle="normal"
android:fontFamily="casual"
android:textSize="18dp"
android:layout_marginLeft="35dp"
android:layout_marginTop="2dp"/>
<TextView
android:id="@+id/tv_selectperson"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/noofperson"
android:layout_toRightOf="@+id/realtime"
android:layout_marginLeft="10dp"
android:text="@string/select_person"
android:fontFamily="casual"
/>
<Spinner
android:id="@+id/spinner"
android:layout_below="@+id/noofperson"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@+id/tv_selectperson">
</Spinner>
<Button
android:id="@+id/btn_closepopup"
android:layout_width="100dp"
android:layout_height="35dp"
android:layout_below="@+id/realtime"
android:layout_alignParentStart="true"
android:layout_alignParentLeft="true"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_marginStart="138dp"
android:layout_marginLeft="138dp"
android:layout_marginTop="11dp"
android:layout_marginEnd="153dp"
android:layout_marginRight="153dp"
android:background="@drawable/circle"
android:fontFamily="casual"
android:text="Book"
android:textSize="10dp" />
</RelativeLayout>