AlertDialog的用法

来源:互联网 发布:sql 存储过程输出 编辑:程序博客网 时间:2024/05/17 07:00

这是写在activity里的代码

 private View choseChapter;  addChapter.setOnClickListener(new View.OnClickListener() {            @Override            public void onClick(View v) {                LayoutInflater inflater = (LayoutInflater) ChapterActivity.this.getSystemService(LAYOUT_INFLATER_SERVICE);                choseChapter= inflater.inflate(R.layout.course_edittext, null);                AlertDialog.Builder dialog=new AlertDialog.Builder(ChapterActivity.this);                dialog.setTitle("请输入要添加的章节名");                dialog.setView(choseChapter);                dialog.setPositiveButton("确定", new DialogInterface.OnClickListener() {                    @Override                    public void onClick(DialogInterface dialog, int which) {                        EditText CourseNmae=(EditText)choseChapter.findViewById(R.id.c);                        String Coursename=CourseNmae.getText().toString();                        if(Coursename.isEmpty())                        {                            Toast.makeText(ChapterActivity.this, "请输入章节号", Toast.LENGTH_SHORT).show();                        }                        else {                            Course c = new Course();                            c.setName(Coursename);                            chapters.add(c);                            adapter.referesh(chapters);                        }                    }                });                dialog.setNegativeButton("取消", new DialogInterface.OnClickListener() {                    @Override                    public void onClick(DialogInterface dialog, int which) {                    }                });                dialog.show();            }        });

这是course_edittext的代码

<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"    android:orientation="vertical" android:layout_width="match_parent"    android:layout_height="match_parent">    <TableLayout        android:layout_width="match_parent"        android:layout_height="wrap_content"        android:id="@+id/tableLayout1">        <TableRow            android:id="@+id/tableRow1"            android:layout_width="wrap_content"            android:layout_height="wrap_content"            android:padding="10dip">            <EditText                android:layout_weight="1"                android:hint="请输入课程名"                android:id="@+id/c"                android:layout_width="wrap_content"                android:layout_height="wrap_content"                ></EditText>        </TableRow>    </TableLayout>    </LinearLayout>
阅读全文
'); })();
0 0
原创粉丝点击
热门IT博客
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 蜂哈哈过量伤子怎么办 八个月宝宝伤食怎么办 床有虫子咬木板怎么办 床的木板有蛀虫怎么办 中蜂发生盗蜂了怎么办 中蜂发生盗蜂怎么办 孕妇给黄蜂蛰了怎么办 被葫芦蜂蜇了怎么办 孕期被蜜蜂蛰了怎么办 怀孕被黄蜂蛰了怎么办 手被黄蜂蛰了怎么办 被懒猴咬了该怎么办 中蜂少于一脾怎么办 比熊吃了巧克力怎么办 马蜂蛰了吃辣椒怎么办 被马蜂蛰到头了怎么办 被马蜂蛰了头怎么办 柿子吃了嘴麻怎么办 头被马蜂咬了怎么办 孩子被蜜蜂蛰了怎么办 小孩被黄蜂蛰了怎么办 手指被蛰了肿了怎么办 被蜜蜂蛰了红肿怎么办 手被蜜蜂蜇肿了怎么办 被马蜂叮了肿了怎么办 被野蜂蛰了肿了怎么办 头被野蜂蛰了怎么办 手指被野蜂咬了怎么办 怀孕被野蜂蛰了怎么办 被马蜂蛰了痒怎么办 被黑色马蜂蛰了怎么办 被大量马蜂蛰了怎么办 被一个马蜂蛰了怎么办 被蜜蜂蛰了头部怎么办 被马蜂蛰了腿怎么办 被马蜂蛰了发痒怎么办 被马蜂蛰了很痛怎么办 被黑马蜂蛰了怎么办 被黄蜂蛰了头部怎么办 被马蜂蛰了痒痒怎么办 蜂把手蛰了肿了怎么办