<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical"> <EditText android:id="@+id/editText" android:layout_height="wrap_content" android:layout_width="fill_parent"/> </LinearLayout>
public class AndroidsCastleActivity extends Activity { protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setTitle("IPアドレスを入力して下さい"); // LayoutInflaterにより動的にレイアウト生成 LayoutInflater inflater = LayoutInflater.from(this); final View view = inflater.inflate(R.layout.main, null); builder.setView(view); builder.setPositiveButton("OK", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int idx) { EditText et = (EditText) view.findViewById(R.id.editText); Log.d("Sample", et.getText().toString()); } }); builder.show(); } }
Portions of this page are modifications
based on work created and shared by Google and used according to terms
described in the Creative Commons 3.0 Attribution License.
- Remical Soft -