私は、.xmlレイアウトファイルを使用するのではなく、キャンバスで画面に描画するためにsurfaceViewを実装する.javaを使用していますが、何らかの点でどうしたらよいかを知りたいと思います。ビューが完了している)、このビューをレイアウトファイルに関連付けたり、ボタンまたはアラートダイアログを呼び出すことができます。キャンバスでAlertDialogを使用する
「あなたが負ける」のようなalerDialogを表示するためにゲームに勝ったり失敗したりするときのように、より明確になるようにします。
Main_Activityは、次のようになります。
public class Main extends Activity {
activity_layout_animation animation;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
animation = new activity_layout_animation(this);
setContentView(animation);
}
@Override
protected void onPause(){
super.onPause();
animation.pause();
}
@Override
protected void onResume(){
super.onResume();
animation.resume();
}
ビューファイルのコードのいくつかの作品:
public class activity_layout_animation extends SurfaceView implements Runnable {
boolean CanDraw = false
public activity_layout_animation(Context context){
super(context);
surfaceHolder = getHolder();
}
@Override
public void run(){
while(CanDraw){
if (!surfaceHolder.getSurface().isValid()){
continue;
}
}
}
編集:私はこのようなsomethigを追加することができます。
AlertDialog.Builder builder;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
builder = new AlertDialog.Builder(context, android.R.style.Theme_Material_Dialog_Alert);
} else {
builder = new AlertDialog.Builder(context);
}
builder.setTitle("Delete entry")
.setMessage("Are you sure you want to delete this entry?")
.setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
// continue with delete
}
})
.setNegativeButton(android.R.string.no, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
// do nothing
}
})
.setIcon(android.R.drawable.ic_dialog_alert)
.show();
それだけで動作しますpublic activity_layout_animation(Context context){
で追加したいrun()
AlertDialogは、XMLからコンテンツビューをロードするか、コード内にコンテンツを作成するかに関係なく、正常に動作するはずです。 AlertDialogを呼び出してみましたか? – cyanide