Skip to content

Instantly share code, notes, and snippets.

@a-v-ebrahimi
Last active December 14, 2019 13:31
Show Gist options
  • Save a-v-ebrahimi/2015332 to your computer and use it in GitHub Desktop.
Save a-v-ebrahimi/2015332 to your computer and use it in GitHub Desktop.
Android: Spinner with custom adapter and layout
String[] ss = getResources().getStringArray(R.array.authors_array);
final String[] items = { ss[1],ss[2],ss[3],ss[4],ss[5],ss[6],ss[7],ss[8],ss[0] };
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("نتيجه جستجو");
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
R.layout.row_for_spinner, R.id.lblText, items);
builder.setAdapter(adapter, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
}
});
builder.show();
//and custom row layout
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="30dp"
android:background="#fff" >
<TextView
android:id="@+id/tvCust"
android:layout_width="wrap_content"
android:layout_height="30dp"
android:layout_toLeftOf="@+id/radioButton1"
android:gravity="left|center_vertical"
android:textColor="#000"
android:textSize="15sp" />
<RadioButton
android:layout_width="wrap_content"
android:layout_height="30dp"
android:layout_alignParentRight="true" />
</RelativeLayout>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment