gpt4 book ai didi

android - 突出显示选定的微调项

转载 作者:太空狗 更新时间:2023-10-29 15:10:34 26 4
gpt4 key购买 nike

我在 wildnove's answer 之后使用 Button 实现了自定义 Spinner .一切正常,但我无法为所选按钮显示突出显示的单选按钮。

下面是代码。

((Button) findViewById(R.id.btnSpinnerPlanets)).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {

// How to highlight Radio button of a selected Item???

final String[] items = view.getResources().getStringArray(R.array.planets__entries);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(MyFormActivity.this, android.R.layout.simple_spinner_dropdown_item, items);
new AlertDialog.Builder(MyFormActivity.this).setTitle("the prompt").setAdapter(adapter, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
((Button) findViewById(R.id.btnSpinnerPlanets)).setText(items[which]);
dialog.dismiss();
}
}).create().show();
}
});

有人可以帮助我如何突出显示所选项目的单选按钮......

最佳答案

不幸的是,这种行为并没有在 Spinner 组件中本地实现,但是,您始终可以创建自己的 BaseAdapter 以在 Spinner 本身或下拉列表中显示您需要的任何天气:

private class ExampleAdapter extends BaseAdapter{

@Override
public int getCount() {
return 0;
}

@Override
public Object getItem(int arg0) {
return null;
}

@Override
public long getItemId(int position) {
return 0;
}

@Override
public View getView(int position, View convertView, ViewGroup parent) {
//Here is where you actually get the chance to return whatever you want in the spinner component (the single bar with the arrow)
return yourCommonView;
}

@Override
public View getDropDownView(int position, View convertView,
ViewGroup parent) {
//Here is where you get the chance to return whatever you want in the dropdown menu so here you should validate what's the currently selected element and return an image accordingly...
return yourSelectedView;
}

}

这里重要的方法是 getDropDownView,它让您有机会返回带有选中的 CheckBox 的元素,或者您想要使用的任何标记,当然您必须创建自己的布局并验证元素是否当前创建的是否需要标记...

问候!

关于android - 突出显示选定的微调项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17022918/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com