CSC的程設紀錄

CSC的程式設計相關研究紀錄、開發日誌

所謂的Hello World...

沒有留言
一般來說,寫程式第一個範例都是Hello World
不過個人習慣加一點料...

Button button = (Button)findViewById(R.id.button);
button.setOnClickListener(buttonAction);

加個Button跟Listener...

private boolean flag = true;
private OnClickListener buttonAction = new OnClickListener(){
public void onClick(View v){
TextView text = (TextView)findViewById(R.id.text);
if (flag){
text.setText(R.string.hello2);
}
else {
text.setText(R.string.hello);
}
flag = !flag;
}
};


按Button則切換兩個String顯示.....
(string.xml)

<string name="hello">Stairway to heaven</string>
<string name="hello2">Highway to hell</string>

然後String一定要用這兩個 XDDDDDDDD

.......還真無聊Orz

沒有留言 :

張貼留言