1

チュートリアルを読んだことがありますが、それ以来、私の電話は XBOX によって全滅されたため、紛失してしまいました。MainActivity に、バージョン番号、現在のバージョンについて、これが対象とする Android のバージョンなどのアプリ情報を示す AlertDialog Box を開くためのボタンが必要です。

 package com.apw.games.rpg.medieval;

import android.app.*;
import android.os.*;
import android.view.*;
import android.widget.*;
import android.content.*;
import android.util.*;
import android.graphics.*;

public class MainActivity extends Activity
{
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
}

@Override public void onNothingSelected(AdapterView<?> parent) {

     }
    @Override 
    public boolean onCreateOptionsMenu(Menu menu) { 
    MenuInflater inflater = getMenuInflater(); 
    inflater.inflate(R.menu.menu, menu); return true; }

    @Override 
    public boolean onOptionsItemSelected(MenuItem item) { 
    // Handle item selection 
    switch (item.getItemId()) { 


        case R.id.quit: 
        Intent intent =  new Intent(this, Exit.class); 
        startActivity(intent); 
        return true; 
        case R.id.new_game: 
            Intent i = new Intent(this, New_Game.class); 
            startActivity(i); 
            return true; 
        case R.id.visit_site: 
            Intent inte = new Intent(this, Site.class); 
            startActivity(inte); 
            return true; 
        default: return super.onOptionsItemSelected(item);

        }}
4

4 に答える 4

6

まず、AlertDialog タイプ オブジェクトを宣言します。

AlertDialog alertDialog = new AlertDialog.Builder(Main.this).create();

Main.this は私のアクティビティのコンテキストです。ダイアログのタイトルは次のように設定できます。

alertDialog.setTitle("Title");

そしてメッセージ:

alertDialog.setMessage("Your text");

次に、ボタンの機能を設定します。

alertDialog.setButton("OK", new DialogInterface.OnClickListener() {
  public void onClick(DialogInterface dialog, int which) {

   //here you can add functions

} });

また、次の行を使用して AlertDialog のアイコンを変更できます。 alertDialog.setIcon(R.drawable.icon);

最後に、ダイアログを表示することを忘れないでください:

alertDialog.show();

于 2012-09-26T11:13:35.530 に答える
2
  AlertDialog.Builder builder = new AlertDialog.Builder(Activity.this)
        .setTitle("alert dialog")
        .setMessage("message")

        .setPositiveButton("ok", new DialogInterface.OnClickListener() {

            public void onClick(DialogInterface dialog, int which) {                            
               Activity.this.finish();  

            }
        })

        .setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
                Activity.this.finish();
            }
        })
        .show();    
于 2012-09-26T11:12:18.077 に答える
-1

The above explanations are good. There are four types of android dialog boxes based on the class types as AlertDialog,Progress Dialog,DatePickerDialog, TimePickerDialog. We can choose based on the need. If its plain dialog to display the messages, just use AlertDialog. If you want to read step by step process to create a dialog, please go through this simple example on how to create alert dialog box in android.

于 2013-01-05T01:18:49.410 に答える