大佬教程收集整理的这篇文章主要介绍了android中的单选选择对话框,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
>下次用户打开对话框时,为所选项目设置背景颜色,
>在对话框中间显示所选项目(这是一个问题,因为大约有20个项目).
这就是我所拥有的:XML:
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://scheR_369_11845@as.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:paddingTop="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 stati@R_772_8592@ SELEctedDatePosition = 0; @Override protected 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(); } }
以上是大佬教程为你收集整理的android中的单选选择对话框全部内容,希望文章能够帮你解决android中的单选选择对话框所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。