Issue
Help me I'm trying to develop app for Sudoku Im stuck at this Im just Bsc First yr guy don't know anything
Here My Xml code for my TextView Code
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/change"
android:text="Not Changed"/>
Here is my XML code for Button
<Button
android:id="@+id/btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="24dp"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:text="Test Button"
app:layout_constraintBottom_toTopOf="@+id/btn_sample"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />
Here is My Java Code
public void btn(View view) {
TextView t=(TextView)findViewById(change);
t.setText("Changed");
}
If I succeed it will Motivate me and my CLG mates I'm noob here sorry for bad English Thanks in Advance
Update : Answer is Solved New code for Button
<Button
android:id="@+id/btn"
android:onClick="btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="24dp"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:text="Test Button"
app:layout_constraintBottom_toTopOf="@+id/btn_sample"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />
New Updated Code for Java
public void btn(View view) {
TextView t=(TextView)findViewById(R.id.change);
t.setText("Changed");
}
Thanks to nilesh-rathod
Solution
Finds a view that was identified by the android:id
XML attribute that was processed in onCreate(Bundle)
.
Use this
TextView t=(TextView)findViewById(R.id.change);
Instead of this
TextView t=(TextView)findViewById(change);
EDIT
If you want to add click event of you Button
than please use below edit
Add android:onclick="btn"
in your Button
<Button
android:id="@+id/btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="24dp"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:onclick="btn"
android:text="Test Button"
app:layout_constraintBottom_toTopOf="@+id/btn_sample"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />
Answered By - AskNilesh
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.