XML ファイルmain.xmlの私のレイアウトは次のとおりです。
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<TextView android:text="hello, world"
android:id="@+id/TextView01"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<Button android:id="@+id/Button01"
android:layout_below="@id/TextView01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:text="OK" />
</RelativeLayout>
アクティビティ コードは次のとおりです。
public class PopupActivity extends Activity implements OnClickListener {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
protected void onStart() {
super.onStart();
final Dialog dialog = new Dialog(this);
dialog.setContentView(R.layout.dialog);
dialog.setTitle("Dialog box");
Button button = (Button) dialog.findViewById(R.id.Button01);
button.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View view) {
dialog.dismiss();
}
});
dialog.show();
}
}
基本的に、スタートアップ時に何かを表示するダイアログ ウィンドウのテスト プログラムを実行したいのですが、R.layout.dialog cannot be resolve at line dialog.setContentView(R.layout.dialog);
What's wrong?が表示されます。ありがとう!