Created
February 25, 2013 08:59
-
-
Save cofearabi/5028587 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" | |
xmlns:tools="http://schemas.android.com/tools" | |
android:layout_width="match_parent" | |
android:layout_height="match_parent" | |
tools:context=".MainActivity" > | |
<TextView | |
android:id="@+id/textView0" | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:layout_centerHorizontal="true" | |
android:layout_centerVertical="true" | |
android:text="@string/hello_world" /> | |
</RelativeLayout> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.example.andrunnable; | |
import android.os.Bundle; | |
import android.os.Handler; | |
import android.os.Message; | |
import android.app.Activity; | |
import android.view.Menu; | |
import android.widget.TextView; | |
public class MainActivity extends Activity implements Runnable { | |
private int counter = 0; | |
public void run() { | |
while(counter < 100){ | |
try { | |
Thread.sleep(30000); | |
} catch (InterruptedException e) {} | |
counter += 1; | |
handler.sendEmptyMessage(0); | |
} | |
} | |
private Handler handler = new Handler() { | |
public void handleMessage(Message msg) { | |
TextView textView = (TextView) findViewById(R.id.textView0); | |
textView.setText("counter="+counter); | |
} | |
}; | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.activity_main); | |
Thread thread = new Thread(this); | |
thread.start(); | |
} | |
@Override | |
public boolean onCreateOptionsMenu(Menu menu) { | |
// Inflate the menu; this adds items to the action bar if it is present. | |
getMenuInflater().inflate(R.menu.activity_main, menu); | |
return true; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment