Android Spinner - 从左到右移动选项

时间:2013-05-21 06:49:07

标签: android

Current spinner look

您好,上面是我当前的微调器的样子。

我想改变一些小事,需要你的帮助:

  1. 将应用程序图标从左向右移动,以便“支持我”位于左侧,而“图标”位于最右侧。
  2. 将圆圈项目从右向左移动。所以我会有一个圆圈,然后是文字。例如(圈子,“评价我”)。
  3. 我想默认设置焦点“rate me”选项,这样当我启动微调器时,它将被选中。我希望内圈呈绿色,也就是突出显示。
  4. 以下是源代码:

    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();
    

    感谢您的帮助,这对像我这样的新手来说非常重要。

    更新:这就是我想要它的样子: enter image description here

    注意第一个选项的默认突出显示效果。我想完全创造那种效果。

1 个答案:

答案 0 :(得分:2)

你必须像这样创建适配器:

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>

有关详细信息,请查看此blog

this link可帮助您管理单选按钮选择(以下是该代码的复选框代码和管理您的选择)