2011-06-26 21 views
0

ここで何が間違っているのですか、何を追加する必要がありますか?アクティビティを使用してダイアログを表示していますか?

package dialog.com; 

import android.app.Activity; 
import android.app.AlertDialog; 
import android.content.DialogInterface; 
import android.app.Dialog; 
import android.os.Bundle; 
import android.view.View; 
import android.widget.Button; 
import android.widget.Toast; 


public class Dialog extends Activity { 
    CharSequence [] items = { "google", "apple", "microsoft" }; 
    boolean [] itemschecked = new boolean [items.length]; 
    /** Called when the activity is first created. */ 
    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.main); 
     Button btn = (Button) findViewById(R.id.btn_dialog); 
     btn.setOnClickListener(new View.OnClickListener() { 
      public void onClick(View v) { 
       showDialog(0); 
      } 
     }); 
    } 
    @Override 
    protected Dialog onCreateDialog(int id) { 
     switch(id) { 
     case 0: 
      return new AlertDialog.Builder(this) 
      .setIcon(R.drawable.icon) 
      .setTitle("This is a Dialog with some simple text...") 
      .setPositiveButton("ok", new 
        DialogInterface.OnClickListener() { 
       public void onClick(DialogInterface dialog, 
         int whichbutton) 
       { 
        Toast.makeText(getBaseContext(), 
          "OK Clicked!", Toast.LENGTH_SHORT).show(); 
      } 
     }); 
      .setNegativeButton("cancel",new 
        DialogInterface.OnclickListener() { 
       public void onClick(DialogInterface dialog, 
         int whichButton) 
       {Toast.makeText(getBaseContext(), 
         "cancel clicked!", Toast.LENGTH_SHORT).show(); 
       } 
      }); 
      .setMultiChoiceItems(itemschecked, new 
        DialogInterface.OnMultiChoiceClickListener() { 
       @Override 
       public void onClick(dialoginterface dialog, int which, boolean isChecked) { 
        Toast.makeText(getBaseContext(), 
          items[which] + (isChecked ? " checked!": 
           "unchecked!"), 
           Toast.LENGTH_SHORT).show(); 
       } 
      } 
      ) 
      .create(); 
     } 
     return null: 

    }}} 
+1

問題は何ですか? – Haphazard

+0

import android.app.Dialogは、同じファイルで定義された型と競合します//戻り値の型はActivity.onCreateDialog(int)と互換性がありません//型の不一致:AlertDialog.BuilderからDialogに変換できません//トークンの構文エラー"。"、このトークンを削除// DialogInterface.OnclickListenerはタイプに解決できません// – ricardo123

答えて

1

Dialog以外のものにあなたのクラスの名前を変更します。それをCustomDialogまたは何かと呼んでください。

+0

ありがとう – ricardo123

1

これは、「Androidアプリケーション開発の開始」の例です。それは働いていなかった

はので、私はこの追加:

  1. import your.package.name.R;
  2. をそして最後@overrideonClick()方法のための1つを削除します。 (注釈を削除するだけではなく、メソッドではありません)
  3. 私はこの行を削除しました:.setIcon(R.drawable.icon)、それを修正できませんでした。

このコードを実行した後。