[Android]入力ボックス(EditText)付きプロンプトボックス(AlertDialog)
2241 ワード
EditTextを表示するレイアウトを新規作成します.
[html] view plain
copy
print ?
xml version="1.0" encoding="utf-8"?>
xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical"
android:layout_width="fill_parent" android:layout_height="fill_parent">
android:layout_width="fill_parent" android:layout_height="wrap_content">
requestFocus>
EditText>
LinearLayout>
Activityに次のように書きます.
[java] view plain
copy
print ?
LayoutInflater factory = LayoutInflater.from(StationActivity.this);//プロンプトボックス final View view = factory.inflate(R.layout.editbox_layout, null);//ここはfinalの でなければなりません
final EditText edit=(EditText)view.findViewById(R.id.editText);//入力ボックスオブジェクトを取得する.
new AlertDialog.Builder(StationActivity.this) .settitle("データなし、範囲を変えてみよう")/プロンプトボックスタイトル .setView(view) .setPositiveButton(「OK」//プロンプトボックスの2つのボタン new android.content.DialogInterface.OnClickListener() { @Override
public void onClick(DialogInterface dialog, int which) {
//イベント }
}).setNegativeButton(「キャンセル」,null).create().show();
(The specified child already has a parent. You must call removeView() on the child's parent first.------>
[html] view plain
copy
print ?
xml version="1.0" encoding="utf-8"?>
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_width="fill_parent"
EditText>
LinearLayout>
Activityに次のように書きます.
[java] view plain
copy
print ?
LayoutInflater factory = LayoutInflater.from(StationActivity.this);//プロンプトボックス
final EditText edit=(EditText)view.findViewById(R.id.editText);//入力ボックスオブジェクトを取得する.
new AlertDialog.Builder(StationActivity.this)
public void onClick(DialogInterface dialog,
//イベント
}).setNegativeButton(「キャンセル」,null).create().show();
(The specified child already has a parent. You must call removeView() on the child's parent first.------>
et1 = new EditText(this);
builder.setView(et1);
)