This is a simple program for beginning (simple for you, not for me) eclipse. I want to change a text by clicking on a button, but it's not working.
Here is the code:
package com.example.androidcourse;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;
import android.R.layout;
public class MainActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.Main);
Button btn = (Button) findViewById(R.id.but_action);
final TextView text = (TextView) findViewById(R.id.txt_caption);
btn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
text.setText("New bingo...");
}
});
}
}
First just build your project. If it will not work, then delete from imports android.R.layout and use layout from your package.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With