Reputation: 1127
Hello, above is what my current spinner looks like.
I would like to change a few small things and need your help:
Below is the source code:
String[] items = new String[] { "Rate me", "Cancel", "Exit" };
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
android.R.layout.simple_spinner_dropdown_item, items);
new AlertDialog.Builder(this).setTitle("Support me")
.setIcon(R.drawable.ic_launcher)
.setAdapter(adapter, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
if (which == 0) {
rate();
}
if (which == 2) {
finish();
}
dialog.dismiss();
}
}).create().show();
Thanks for your help, it's very important to a newbie like me.
UPDATE: Here's what I want it to like like:
Notice the default highlight effect on the first option. I want to create that effect exactly.
Upvotes: 0
Views: 702
Reputation: 18978
you have to create adapter like this way:
package com.example.test_all;
import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ListView;
import android.widget.RadioButton;
import android.widget.TextView;
public class MainActivity extends Activity {
private ListView List;
String a[] = { "a", "b", "c", "d", "e" };
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
List = (ListView) findViewById(R.id.listView1);
List.setAdapter(new ListViewAdapter(MainActivity.this));
}
public class ListViewAdapter extends BaseAdapter {
private LayoutInflater mInflater;
public ListViewAdapter(Context con) {
// TODO Auto-generated constructor stub
mInflater = LayoutInflater.from(con);
}
public int getCount() {
// TODO Auto-generated method stub
return a.length;
}
public Object getItem(int position) {
// TODO Auto-generated method stub
// return product_id1.size();
return position;
}
public long getItemId(int position) {
// TODO Auto-generated method stub
// return product_id1.get(position).hashCode();
return position;
}
public View getView(final int position, View convertView,
ViewGroup parent) {
// TODO Auto-generated method stub
final ListContent holder;
View v = convertView;
if (v == null) {
v = mInflater.inflate(R.layout.custom, null);
holder = new ListContent();
holder.name = (TextView) v.findViewById(R.id.textView1);
holder.rad = (RadioButton) v.findViewById(R.id.radioButton1);
// holder.total_rate.setOnClickListener(mOnTitleClickListener1);
v.setTag(holder);
} else {
holder = (ListContent) v.getTag();
}
holder.name.setText("" + a[position]);
return v;
}
}
static class ListContent {
TextView name;
RadioButton rad;
}
}
custom.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center"
android:weightSum="5"
android:orientation="horizontal" >
<RadioButton
android:id="@+id/radioButton1"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:text="" />
<TextView
android:id="@+id/textView1"
android:layout_width="0dp"
android:layout_weight="4"
android:layout_height="wrap_content"
android:text="Medium Text"
android:textAppearance="?android:attr/textAppearanceMedium" />
</LinearLayout>
for more detail check this blog
this link help you to manage radiobutton selection(Here is code of checkbox take idea from that code & manage your selection)
Upvotes: 2