老师能帮我看一下 单选对话框哪儿出问题了吗,我用手机调试 单选对话框不会弹出来
package com.example.dateandtimedialog; import android.app.AlertDialog; import android.app.DatePickerDialog; import android.content.DialogInterface; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.view.View; import android.widget.DatePicker; import android.widget.TextView; import android.widget.Toast; import java.util.Calendar; public class MainActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); TextView tc=findViewById(R.id.text_view); } public void myClick(View view){ switch (view.getId()){ case R.id.date_set_dialog: DatePickerDialog dll= new DatePickerDialog(MainActivity.this, new DatePickerDialog.OnDateSetListener() { @Override public void onDateSet(DatePicker view, int year, int month, int dayOfMonth) { Toast.makeText(MainActivity.this,Integer.toString(year)+"年"+Integer.toString(month+1)+"月"+Integer.toString(dayOfMonth)+"日",Toast.LENGTH_LONG).show(); } }, Calendar.DAY_OF_YEAR,Calendar.DAY_OF_MONTH,Calendar.DATE); dll.show(); break; case R.id.sex_select_dialog: AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this); builder.setTitle("性别选择"); builder.setIcon(R.drawable.ic_launcher_background); builder.setSingleChoiceItems(R.array.sex_string,android.R.layout.simple_selectable_list_item, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { Toast.makeText(MainActivity.this,"你选择了:"+Integer.toString(which),Toast.LENGTH_SHORT).show(); dialog.dismiss(); } }); builder.show(); break; } } }
<resources> <string name="app_name">DateAndTimeDialog</string> <string-array name="sex_string"> <item>男</item> <item>女</item> <item>性别未知</item> <item>你猜</item> </string-array> <string-array name="habbit_string"> <item>编程</item> <item>LOL</item> <item>旅游</item> <item>篮球</item> </string-array> </resources>
5
收起
正在回答 回答被采纳积分+1
2回答
1.Android 零基础入门
- 参与学习 人
- 提交作业 1789 份
- 解答问题 2907 个
Android大楼Java起,本阶段是Android攻城狮培养计划的第一部分语法与界面基础篇,将带大家从0开始入门Android开发。
了解课程
恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧
0 星