Android App Development | Lecture#19 Code Issues Fix | Hive Learners
𝓖𝓻𝓮𝓮𝓽𝓲𝓷𝓰𝓼
Hello, beautiful members of the community. In lecture 19 we wrote all the logic for all the calculator buttons. Today when I am getting ready for our new app journey I found some mistakes in our java code. These are small mistakes but we need to cover them. I am also thankful for @eniolw for notifying me about a spelling mistake that we have made throughout the android app development series. Our thumbnail contains the word Andriod and I fixed it today. Thanks.
GitHub Link
Use this GitHub project to clone into your directory. It will constantly get updated in the following lecture so you will never miss the latest code. Happy Coding!.
What Should I Learn
- Fix the issues of Lecture 19
Assignment
- Show the correct answer on screen1.
Procedure
The first mistake that we made is, We skip the testing of our code at the end of the lecture. Today I calculate two numbers and something is missing on the screen. Let's check it first.
So we need to change a line of code in the equal_btn click listener. When the button click we need to pick the text first and store it in a variable as we did in the first_num variable. We also need to change the data type for first_num. We will use float
Here is the code for the plus sign and then we will use the same logic for other operations accordingly.
String stored_sign = screen2_tv.getText().toString();
float second_num = Float.parseFloat(screen1_tv.getText().toString());
if (stored_sign.equals("+")) {
float result = first_num + second_num);
screen1_tv.setText(first_num + stored_sign + second_num + " = " + result);
Now run the app and check the result.
We also need to fix the code for the trim_btn. If there is no text on the screen1 is crashing the app sometimes. So here we use the length rather than check the empty text in screen1. This will fix the crash on the trim button click for any time.
if (screen1_tv.getText().length() > 0) {
screen1_tv.setText(screen1_tv.getText().toString().substring(0, screen1_tv.getText().length() - 1));
}
Thanks for your contribution to the STEMsocial community. Feel free to join us on discord to get to know the rest of us!
Please consider delegating to the @stemsocial account (85% of the curation rewards are returned).
You may also include @stemsocial as a beneficiary of the rewards of this post to get a stronger support.
Congratulations @faisalamin! You have completed the following achievement on the Hive blockchain and have been rewarded with new badge(s):
Your next target is to reach 25000 upvotes.
You can view your badges on your board and compare yourself to others in the Ranking
If you no longer want to receive notifications, reply to this comment with the word
STOP
Check out the last post from @hivebuzz:
It is important to fix all the bugs for a good work
!1UP
You have received a 1UP from @gwajnberg!
@stem-curator
And they will bring !PIZZA 🍕.
Learn more about our delegation service to earn daily rewards. Join the Cartel on Discord.