Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Code for session 3
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="5dp"
android:orientation="vertical">
<TextView
android:textAllCaps="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:text="Guess"/>
<TextView
android:id="@+id/current_guess"
android:textColor="@android:color/black"
android:textSize="16sp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginTop="8dp"
android:text="0"/>
<Button
android:layout_marginTop="8dp"
android:onClick="submitOrder"
android:text="SUBMIT"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</LinearLayout>
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.TextView;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
/**
* This method is called when the order button is clicked.
*/
public void submitOrder(View view) {
// try changing this number
display(1);
}
/**
* This method displays the given quantity value on the screen.
*/
private void display(int number) {
TextView quantityTextView = findViewById(R.id.current_guess);
quantityTextView.setText("" + number);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment