0
基於更改textview我希望對話框根據所選的選項顯示正確的文本(即如果按下兩個我想顯示文本「你按兩個」)試圖獲得一個alertdialog基於選擇的選項
第一按下它似乎什麼也不做文字進入到初始化 第二按你找出文本切換到默認
我是新來的Android和我不認爲我明白了什麼活動正在這裏做。 有人可以幫我找到一種有效的方法嗎?
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();
}
這會導致當按下按鈕部隊密切,這不是我的問題,只是說我盡力了!
logcat說什麼?! – binnyb
關於力量關閉? – Jill