>下次用户打开对话框时,为所选项目设置背景颜色,
>在对话框中间显示所选项目(这是一个问题,因为大约有20个项目).
这就是我所拥有的:XML:
<?xml version="1.0" enCoding="utf-8"?> <linearLayout xmlns:androID="http://schemas.androID.com/apk/res/androID" androID:layout_wIDth="fill_parent" androID:layout_height="fill_parent" androID:orIEntation="vertical" ><linearLayout androID:layout_wIDth="match_parent" androID:layout_height="wrap_content" androID:@R_301_5095@top="5dp" > <button androID:ID="@+ID/selectDatebutton" androID:layout_wIDth="match_parent" androID:layout_height="wrap_content" androID:text="Please,select date" /></linearLayout>
JAVA:
public class ExperimentListVIEw extends Activity {private static final DateFormat DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd");private static Calendar calendar = Calendar.getInstance();private static button selectDatebutton;private static String[] items;private static int selectedDateposition = 0;@OverrIDeprotected voID onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentVIEw(R.layout.List_vIEw_ex); selectDatebutton = (button)findVIEwByID(R.ID.selectDatebutton); selectDatebutton.setonClickListener(new OnClickListener() { @OverrIDe public voID onClick(VIEw v) { items = new String[20]; for (int i = 0; i < 20; i++) { items[i] = DATE_FORMAT.format(calendar.getTime()); calendar.add(Calendar.DATE,1); } showListVIEw(); } });}private voID showListVIEw() { AlertDialog.Builder builder = new AlertDialog.Builder(ExperimentListVIEw.this); builder.setTitle("Select date"); builder.setItems(items,new DialogInterface.OnClickListener() { @OverrIDe public voID onClick(DialogInterface dialog,int which) { selectedDateposition = which; selectDatebutton.setText(items[selectedDateposition]); } }); AlertDialog alertDialog = builder.create(); alertDialog.getListVIEw().setSelection(selectedDateposition); alertDialog.show(); }}
到目前为止,我还没有找到解决方案,如果有人可以提供帮助,我将不胜感激.
提前致谢.
builder.setSingleChoiceItems(strArray,selected_pos,new DialogInterface.OnClickListener () { @OverrIDe public voID onClick(DialogInterface dialog,int which) { } });总结
以上是内存溢出为你收集整理的android中的单选选择对话框全部内容,希望文章能够帮你解决android中的单选选择对话框所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)