綁定帳號登入

Android 台灣中文網

打印 上一主題 下一主題

[求助] .setText 問題

[複製連結] 查看: 1287|回覆: 3|好評: 0
跳轉到指定樓層
樓主
ricky52_be7 | 收聽TA | 只看該作者 回帖獎勵 |倒序瀏覽 |閱讀模式
發表於 2012-5-11 22:00

馬上加入Android 台灣中文網,立即免費下載應用遊戲。

您需要 登錄 才可以下載或查看,沒有帳號?註冊

x
怎將int的東西放在.setText()??
或是將int轉類?
「用Android 就來APK.TW」,快來加入粉絲吧!
Android 台灣中文網(APK.TW)
收藏收藏 分享分享 分享專題
用Android 就來Android 台灣中文網(https://apk.tw)
回覆

使用道具 舉報

沙發
ploglin | 收聽TA | 只看該作者
發表於 2012-5-14 08:39
int x = 10;
xxx.setText(Integer.valueOf(x));
用Android 就來Android 台灣中文網(https://apk.tw)
回覆 支持 反對

使用道具 舉報

板凳
 樓主| ricky52_be7 | 收聽TA | 只看該作者
發表於 2012-5-14 17:59

可以看看有什麼問題嗎?
按Button時,仍然沒有回應...

package ricky.result;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

public class ResultActivity extends Activity {
    /** Called when the activity is first created. */
        private Button red, yellow, blue, green;
        int r = 0;
    int y = 0;
    int b = 0;
    int g = 0;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
        red=(Button)findViewById(R.id.red);
        yellow=(Button)findViewById(R.id.yellow);
        blue=(Button)findViewById(R.id.blue);
        green=(Button)findViewById(R.id.green);
        
        red.setOnClickListener(newListener);
        yellow.setOnClickListener(newListener);
        blue.setOnClickListener(newListener);
        green.setOnClickListener(newListener);
    }
   
    private Button.OnClickListener newListener = new Button.OnClickListener(){
            public void onClick(View v){
                    switch(v.getId()){
                    case R.id.red:
                    {
                            r++;
                            red.setText(Integer.valueOf(r));
                            break;
                    }
                       case R.id.yellow:
                    {
                            y++;
                            yellow.setText(Integer.valueOf(y));
                            break;
                    }
                       case R.id.blue:
                    {
                            b++;
                            blue.setText(Integer.valueOf(b));
                            break;
                    }
                       case R.id.green:
                    {
                            g++;
                            green.setText(Integer.valueOf(y));
                            break;
                    }
            }
    }
};
}
用Android 就來Android 台灣中文網(https://apk.tw)
回覆 支持 反對

使用道具 舉報

地板
ploglin | 收聽TA | 只看該作者
發表於 2012-5-16 11:19
不好意思,之前回覆錯了,寫法應該是

  1. green.setText(Integer.toString(y));
複製代碼
用Android 就來Android 台灣中文網(https://apk.tw)
回覆 支持 反對

使用道具 舉報

您需要登錄後才可以回帖 登錄 | 註冊

本版積分規則