2011-07-15 10 views
0

選択したオプションに基づいて正しいテキストを表示するようにダイアログを表示したいとします(2回押した場合は「2回押しました」というテキストを表示します)選択したオプションに基づいてテキストビューを変更するためのアラートダイアログを取得しようとしています

初回の

それは一見テキストはテキストを見つける第2のプレスに初期化さ に行く何も

をデフォルトに切り替えなかったん私はアンドロイドに新たなんだと私は私が何を理解してないと思いますここで活動が行われています。 誰かが働く方法を見つけるのを手伝ってもらえますか?

public class AndMainT extends Activity { 
private GameLogicT myGame = new GameLogicT(); 

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

    Button b_com = (Button)findViewById(R.id.button); 
    b_com.setOnClickListener(new View.OnClickListener() { 
     public void onClick(View v) { 
      CharSequence[] pick_one = {"ONE", "TWO", "THREE"}; 
      call_menu(pick_one); 
      updateAwesomeText(); 
     } 
    }); 
} 

public void updateAwesomeText(){ 
    TextView newText = (TextView)findViewById(R.id.text); 
    newText.setText(myGame.getCurrent_opt().getDescription() + "\n"); 
} 

public void call_menu(CharSequence[] items){ 
    final CharSequence[] f_items = items; 

    AlertDialog.Builder builder = new AlertDialog.Builder(this); 
    builder.setTitle("Orders Captain?"); 
    builder.setItems(f_items, new DialogInterface.OnClickListener() { 
     public void onClick(DialogInterface dialog, int item) { 
      myGame.startOpt(item); 
     } 
    }); 
    builder.show(); 
} 
} 


public class GameLogicT { 
class GOpt{ 
    private CharSequence description = "this is the intialized text sadface"; 

    public CharSequence getDescription() { 
     return description; 
    } 
    public void setDescription(CharSequence description) { 
     this.description = description; 
    } 
} 

private GOpt current_opt = new GOpt(); 

public void startOpt(int item){ 
    switch(item){ 
    case 1: 
     current_opt.setDescription("you pressed ONE"); 
    case 2: 
     current_opt.setDescription("you pressed TWO"); 
    case 3: 
     current_opt.setDescription("you pressed THREE"); 
    default: 
     current_opt.setDescription("I am a fart and think you have pressed nothing sadface"); 
    } 
} 

public GOpt getCurrent_opt() { 
    return current_opt; 
} 
public void setCurrent_opt(GOpt current_opt) { 
    this.current_opt = current_opt; 
} 
} 

私はまた、これは、ボタンが押されたとき、私の質問は、ちょうど私が試したと言っていない力の近くを起こし

public void onClick(View v) { 
     CharSequence[] pick_one = {"ONE", "TWO", "THREE"}; 
     call_menu(pick_one); 
     try { 
       wait(); 
      } catch (InterruptedException e) { 
       e.printStackTrace(); 
      } 
     updateAwesomeText(); 
    } 

    public void onClick(DialogInterface dialog, int item) { 
     myGame.startOpt(item); 
     notify(); 
    } 

を試してみました!

+0

logcatとは何ですか? – binnyb

+0

力が閉じるのは? – Jill

答えて

0

申し訳ありませんが、私は多くの作業のためにあなたのコードをテストすることはできません。 はしかし、見た目を取った後、私は次のように気づいた:

1)私はたぶん、あなたはswitch-caseの文ので

にいくつかbreakを失った、交換してみてください)アイテムの位置は、インデックス0 2から始まると思いますそれで:

public void startOpt(int item){ 
    switch(item){ 

    case 0: 
     current_opt.setDescription("you pressed ONE"); 
    break; 

    case 1: 
     current_opt.setDescription("you pressed TWO"); 
    break; 

    case 2: 
     current_opt.setDescription("you pressed THREE"); 
    break; 

    default: 
     current_opt.setDescription("I am a fart and think you have pressed nothing sadface"); 
    } 
} 

あなたが助けてくれることを願っています!

関連する問題