-
-
Save udacityandroid/6c8a127ff0a3c29721af to your computer and use it in GitHub Desktop.
Android Development for Beginners : Practice Set 2 Sleep Debt Example
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
int weekday = 5; | |
int weekend = 9; | |
int optimalHours = 7 * 8; | |
int actualHours = weekday; | |
actualHours = actualHours + weekend * 2; | |
int solution = optimalHours - actualHours; | |
display(solution); |
@yyssimon
I think you have a display method in the MainActivity onCreate{}.
Try putting it outside {} of onCreate.
Example:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// PASTE CODE YOU WANT TO TEST HERE
int weekday = 5;
int weekend = 9;
int optimalHours = 7 * 8;
int actualHours = weekday;
actualHours = actualHours + weekend * 2;
int solution = optimalHours - actualHours;
display(solution);
}
public void display(int i) {
TextView t = (TextView) findViewById(R.id.display_text_view);
t.setText("" + i);
}
In case its 2021 with updated android studio.. and the old code has some buggs..
try this one it worked for me.
package com.example.android.practiceset2;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.TextView;
import androidx.appcompat.app.AppCompatActivity;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
int weekday = 5;
int weekend = 9;
int optimalHours = 7 * 8;
int actualHours = weekday;
actualHours = actualHours + weekend * 2;
int solution = optimalHours - actualHours;
display(solution);
}
/**
* 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 (int i) {
TextView t = (TextView) findViewById(R.id.display_text_view);
t.setText(""+i);
}
}
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Anyone can help me on this please?