Skip to content

Instantly share code, notes, and snippets.

@akshayrajkumar
Created January 19, 2018 07:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save akshayrajkumar/26fe0c614b2aff09b3f9fdf2f75681ec to your computer and use it in GitHub Desktop.
Save akshayrajkumar/26fe0c614b2aff09b3f9fdf2f75681ec to your computer and use it in GitHub Desktop.
Udacity android development PractiecSet2 Lesson 3 , Experimenting with code
package com.example.android.practiceset2;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.widget.TextView;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// PASTE CODE YOU WANT TO TEST HERE
int raspberryPrice = 5;
display1("1 box: $" + raspberryPrice);
display2("2 boxes: $" + (raspberryPrice*2));
display3("3 boxes: $" + (raspberryPrice * 3));
}
/**
* Display methods that allow the text to appear on the screen. Don't worry if you don't know
* how these work yet. We'll be covering them in lesson 3.
*/
public void display(String text) {
TextView t = (TextView) findViewById(R.id.display_text_view);
t.setText(text);
}
// public void display(int text) {
// TextView t = (TextView) findViewById(R.id.display_text_view);
// t.setText(text + "");
// }
public void display1(String text) {
display(text);
}
public void display2(String text) {
TextView t = (TextView) findViewById(R.id.display_text_view_2);
t.setText(text);
}
public void display3(String text) {
TextView t = (TextView) findViewById(R.id.display_text_view_3);
t.setText(text);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment