Professional Documents
Culture Documents
Exp 26
Exp 26
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="30dp"
android:id="@+id/t1"
android:layout_marginTop="20dp"
/>
<EditText
android:id="@+id/et1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="280dp"
android:layout_marginTop="20dp"
android:ems="10"
android:inputType="number"
tools:ignore="TouchTargetSizeCheck,SpeakableTextPresentCheck" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/b1"
android:textSize="20dp"
android:layout_marginTop="70dp"
android:layout_marginLeft="70dp"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/t2"
android:layout_below="@id/b1"
android:layout_marginLeft="140dp"
android:textSize="20dp"/>
</RelativeLayout>
MAIN ACTIVITY.JAVA
Button b1;
EditText et1;
@SuppressLint("MissingInflatedId")
@Override
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
b1 = (Button) findViewById(R.id.b1);
t1 = (TextView) findViewById(R.id.t1);
t2 = (TextView) findViewById(R.id.t2);
b1.setOnClickListener(new View.OnClickListener() {
@Override
runner.execute(sleepTime);
});
private class AsyncTaskRunner extends AsyncTask<String, String, String> {
String resp;
ProgressDialog progressDialog;
@Override
publishProgress("Sleeping");
try {
Thread.sleep(time);
} catch (InterruptedException e) {
e.printStackTrace();
} catch (Exception e) {
resp = e.getMessage();
return resp;
@Override
progressDialog.dismiss();
t2.setText(result);
@Override
@Override
t2.setText(text[0]);