java單向鏈表的完成實例。本站提示廣大學習愛好者:(java單向鏈表的完成實例)文章只能為提供參考,不一定能成為您想要的結果。以下是java單向鏈表的完成實例正文
1.創立一個包括ScrollView的結構文件:
2.完成ScrollView的刷新
package com.example.uirefresh;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ScrollView;
import android.widget.TextView;
public class MainActivity extends Activity implements android.view.View.OnClickListener{
private Button btnExit;
private TextView text;
private ScrollView scroll;
private boolean bool = true;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
btnExit = (Button) findViewById(R.id.exit);
text = (TextView) findViewById(R.id.text);
scroll = (ScrollView) findViewById(R.id.scroll);
btnExit.setOnClickListener(this);
//在主線程main中開一子線程來刷新部分的ScrollView
new Thread(new RefreshThread()).start();
}
@Override
public void onClick(View v) {
switch(v.getId()) {
case R.id.exit :
finish();
break;
}
}
public class RefreshThread implements Runnable{
@Override
public void run() {
while(bool) {
try {
Thread.sleep(5000);//每五秒刷新一次
} catch (InterruptedException e) {
e.printStackTrace();
}
synchronized (this) {
//用post辦法刷新
text.post(new Runnable() {
@Override
public void run() {
text.append("Hello World...n");
}
});
}
}
}
}
@Override
protected void onDestroy(){
super.onDestroy();
bool = false;
}
}