0

在 Google Now 的“提醒”功能中,您可以在收到日历视图提示并选择日期后设置日期。我注意到,一旦选择了日期,Spinner 显示的文本就是选择的日期,但是在下拉列表中找不到该项目。我想对我的代码做同样的事情。

提醒的微调器能力

4

2 回答 2

0

为默认的“4 月 24 日星期四”视图和下拉列表创建自定义SpinnerAdapter和覆盖。要将数据绑定到您的,请调用。Adapter.getViewSpinnerAdapter.getDropDownViewSpinnerSpinner.setAdapter

public class YourAdapter extends BaseAdapter {

    @Override
    public int getCount() {
        // How many items are in the data set represented by this Adapter
        return 0;
    }

    @Override
    public Object getItem(int position) {
        // Get the data item associated with the specified position in the data
        // set.
        return null;
    }

    @Override
    public long getItemId(int position) {
        // Get the row id associated with the specified position in the list
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        // Get a View that displays the data at the specified position in the
        // data set
        return null;
    }

    @Override
    public View getDropDownView(int position, View convertView, ViewGroup parent) {
        // Get a View that displays in the drop down popup the data
        // at the specified position in the data set
        return super.getDropDownView(position, convertView, parent);
    }

}

final Spinner spinner = ...;
spinner.setAdapter(new YourAdapter());
于 2014-04-18T23:05:31.653 回答
0

您必须扩展 Adapter 子类,然后覆盖 getView() 方法。

public class NavigationSpinnerAdapter extends ArrayAdapter {

public NavigationSpinnerAdapter(Context context, int resource, int textViewResourceId, List objects) {
    super(context, resource, textViewResourceId, objects);
}

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    TextView view = (TextView) super
            .getView(position, convertView, parent);
    view.setText("Thursday, April 24");
    return view;
}
}

然后你像这样使用它:

final ActionBar actionBar = getActionBar();
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_LIST);
ArrayList<String> itemList = new ArrayList<String>();
itemList.add("Today");
itemList.add("Tomorrow");
itemList.add("Set Date...");
ArrayAdapter<String> arrayAdapter = new NavigationSpinnerAdapter(this, android.R.layout.simple_spinner_dropdown_item, android.R.id.text1, itemList);
actionBar.setListNavigationCallbacks(arrayAdapter, this);
于 2014-07-21T18:27:30.297 回答