
저 써져있는 i가 1초마다 0부터 차례대로 올라가게 하고 싶은데 디버깅하면 회색하면으로 아무것도 안뜨다가 10초가 지나면(아마 while문을 다 돌고 나면) 배경 이미지들이랑 같이 i=9로 한번에 그려집니다. AsyncTask도 써보고 별 짓을 다 해봤는데 계속 그러네요 저 이미지들은 xml로 작성하고 자바코드로 작성하지는 않았습니다.
public class MainActivity extends AppCompatActivity{
private ImageButton mSendMessage;
private LinearLayout mMessageLog;
private TextView text;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mMessageLog = (LinearLayout)findViewById(R.id.message_log);
ExampleThread thread = new ExampleThread();
thread.start();
}
private class ExampleThread extends Thread {
private static final String TAG = "ExampleThread";
private TextView text;
private int i;
public ExampleThread() {
// 초기화 작업
text = new TextView(MainActivity.this);
mMessageLog.addView(text);
}
public void run() {
runOnUiThread(new Runnable() {
@Override
public void run() {
// 스레드에게 수행시킬 동작들 구현
while(i<10)
{
try {
text.setText("i="+i);
i++;
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
});
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}