1. android的聊天界面時間怎麼顯示的
你這樣直接修改主頁面,像你這樣比較消耗時間的操作的話,系統一般來說是不會響應的,你應該放到線程裡面執行這樣比較耗時的操作
你可以這樣寫:
public class TestActivity extends Activity {
private static final int msgKey1 = 1;
private TextView mTime;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.time);
Time = (TextView) findViewById(R.id.time);
new TimeThread().start();
}
public class TimeThread extends Thread {
@Override
public void run () {
do {
try {
Thread.sleep(1000);
Message msg = new Message();
msg.what = msgKey1;
mHandler.sendMessage(msg);
}
catch (InterruptedException e) {
e.printStackTrace();
}
} while(true);
}
}
private Handler mHandler = new Handler() {
@Override
public void handleMessage (Message msg) {
super.handleMessage(msg);
switch (msg.what) {
case msgKey1:
long sysTime = System.currentTimeMillis();
CharSequence sysTimeStr = DateFormat.format("hh:mm:ss", sysTime);
Time.setText(sysTimeStr);
break;
default:
break;
}
}
};
}