I would like the 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);
}
}
But I could not do it, so I put 0 to appear something in the image of the emulator and it becomes easier to understand what I would like to do.
Iwouldlikethebuttontochangethevalueofthevariabletoincreaseby1andtohavethetextViewupdated.
Iwouldalsoliketoknowifitwasnecessarytoputprivateorpublicbeforehavingdeclaredtheintegervariableint,type:
privateintnumero=0;
or
publicintnumero=0;
activity_main.xml
<?xmlversion="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>