-
-
Save udacityandroid/332432b53a13e5c55c1c to your computer and use it in GitHub Desktop.
Android Development for Beginners : Starter Gist for XML
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
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" | |
xmlns:tools="http://schemas.android.com/tools" | |
android:layout_width="match_parent" | |
android:layout_height="match_parent" | |
android:orientation="vertical" | |
tools:context="com.example.android.practiceset2.MainActivity"> | |
<TextView | |
android:id="@+id/display_text_view" | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:text="" | |
android:textSize="45sp" /> | |
<TextView | |
android:id="@+id/display_text_view_2" | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:text="" | |
android:textSize="45sp" /> | |
<TextView | |
android:id="@+id/display_text_view_3" | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:text="" | |
android:textSize="45sp" /> | |
</LinearLayout> |
one suggestion from my side :- DO NOT COPY-PASTE THE CODE AS TOLD BY THE INSTRUCTOR.
rather build up the code as given here in the gist.
actually i had issue of app crashes and what not.
i made a new project and rebuilt the code on my own and it worked
In activity_main.xml file
Replace this: tools:context="com.example.android.practiceset2.MainActivity">
To this: tools:context="com.example.practiceset2.MainActivity">
and in MainActivity.java file
This is the Final Working code for me.
I'm using Windows 10 (64 bit), and android studio 4.2 (beta 4).
_I tried the solution by @fedor90 and then the following code:_
### **for "activity_main.xml":**
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="com.example.practiseset2.MainActivity">">
<TextView
android:id="@+id/display_text_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=""
android:textSize="45sp" />
<TextView
android:id="@+id/display_text_view_2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=""
android:textSize="45sp" />
<TextView
android:id="@+id/display_text_view_3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=""
android:textSize="45sp" />
</LinearLayout>
**### for "MainActivity.java "**
package com.example.practiseset2;
import android.os.Bundle;
import androidx.appcompat.app.AppCompatActivity;
import android.widget.TextView;
import com.example.practiseset2.R;
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
}
/**
* 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);
}
}
``
for those who are facing a issue with unable to resolve display_text_view issue just check your text view id because in my id "+" was not present
Thank you!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Guys don't worry, just try a solution.
In activity_main.xml file
Replace this: tools:context="com.example.android.practiceset2.MainActivity">
To this: tools:context="com.example.practiceset2.MainActivity">
and in MainActivity.java file
Replace this: package com.example.android.practiceset2;
To this: package com.example.practiceset2;