0
I would like textView to display the value of the variable I created in Mainactivity "int numero = 0".
package genesysgeneration.a10;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.Button;
public class MainActivity extends AppCompatActivity {
int numero = 0;
private Button btnMais1;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
btnMais1=(Button)findViewById(R.id.btnMais1);
}
}
However I could not do it, so I put 0 to appear something in the emulator image and make it easier to understand what I would like to do.
I would like when clicking the button the value of the variable increased by 1 and the textView was updated.
I would also like to know if it was necessary to put private or public before declaring the integer variable int, type:
private int numero = 0;
or
public int numero = 0;
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="genesysgeneration.a10.MainActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:id="@+id/tvContador"
android:text="0" />
<Button
android:text="+ 1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:id="@+id/btnMais1" />
</RelativeLayout>
THANK YOU SO MUCH BRO!!! VLW REALLY!!! Now if it’s not too much trouble, I wonder if I could put this public void outside of "@Override"?
– Boneco Sinforoso
look at the code now
– itscorey
THANK YOU!!! Soon I will try to do something similar to checkbox.
– Boneco Sinforoso