我的只能是AlertDialog builder不能是AlertDialog.Builder

来源:2-11 输入对话框

注定不同

2018-06-26 21:45:29

import android.support.v7.app.AlertDialog;

。。。

private void showSingleListDialog() {
   final String[] fruit = {"apple", "banana", "orange", "pear", "peach"};

// 此处和老师的不一样,而且不能写成老师那样的,不知道为什么?

   AlertDialog builder = new AlertDialog.Builder(this)
           .setTitle("单选列表提示,喜欢的水果").setSingleChoiceItems(fruit, 1, new DialogInterface.OnClickListener() {
               @Override
               public void onClick(DialogInterface dialogInterface, int i) {
                   idx = i;
               }
           }).setPositiveButton("确定", new DialogInterface.OnClickListener() {
               @Override
               public void onClick(DialogInterface dialogInterface, int i) {
                   Toast.makeText(MainActivity.this, fruit[idx], Toast.LENGTH_SHORT).show();
               }
           }).show();
}


写回答

1回答

注定不同

提问者

2018-06-26

http://img.mukewang.com/climg/5b3244a20001bb2f04690171.jpg

这个问题报的是这个错

0
hender10
h 在Module的build.gradle中是否导入了compile 'com.android.support:appcompat-v7:23.1.1'
h018-06-27
共1条回复

0 学习 · 1044 问题

查看课程