• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps Help on code

rtfpessoa

Lurker
I'm making my first android app and i'm having some problems.
Can anybody help me creating an app with one button that when is pressed a Number in the screen increases one value.

My actual code:

Code:
package com.rodrigo;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

public class Contador_IAED extends Activity {
    /** Called when the activity is first created. */
	int count;
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
    
    Button startButton = (Button) findViewById(R.id.trigger);
    startButton.setOnClickListener(new View.OnClickListener() {
    	public void onClick(View view) { 
    		++count;
    		}
    	
    });
    TextView tv = (TextView) findViewById(R.id.hello_text);
    tv.setText(count);
}}
 
You need to have the button update the text:

startButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
++count;
TextView tv = (TextView) findViewById(R.id.hello_text);
tv.setText(count);
}
});
 
Back
Top Bottom