Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

This article is a Private article. Only a writer and users who know the URL can access it.
Please change open range to public in publish setting if you want to share this article with other users.

More than 5 years have passed since last update.

文字入力のできるダイアログ生成

Last updated at Posted at 2016-12-02

editTextとOKボタン、キャンセルボタンのあるダイアログを生成する方法を紹介します

EditDialog
AlertDialog.Builder editDig;
Dialog mAlertDig;
EditText title;
LayoutInflater inflater;
View edit;

inflater=(LayoutInflater)this.getSystemService(LAYOUT_INFLATER_SERVICE);
        edit=inflater.inflate(R.layout.dialog_edit,(ViewGroup)lfindViewById(R.id.layout_dialog));
        editDig=new AlertDialog.Builder(this);
        editDig.setTitle("新規作成");
        editDig.setView(edit);
        title=(EditText)edit.findViewById(R.id.dialog_edittext);
editDig.setPositiveButton("OK", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
               
            }
        });
        editDig.setNegativeButton("キャンセル", null);
        mAlertDig=editDig.create();

editTextをダイアログに入れるとき、注意すべき点はinflateしたView(この場合、editとなる)をfindViewByIdの前に入れておく必要がある。入れないとダイアログで入力された文字が画面に表示されない

edit=inflater.inflate(R.layout.dialog_edit,(ViewGroup)
title=(EditText)edit.findViewById(R.id.dialog_edittext);

このプログラムの実行結果は
Screenshot_20161202-105933.png

0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?