
Originally Posted by
jmejiaa
I havent looked much into the layouts and how to change them, but for a button press you need to create an event listener,, see below:
final Button ButtonName= (Button) findViewById(R.id.buttonID);
ButtonName.setOnClickListener(new View.OnClickListener()
{
public void onClick(View v)
{
// Your code here
}
});
Ok to specify my question a bit more based on this:
Take this code here, taken from a standard hello world project that I have continued to build on, if I wanted to make buttons work with this, where would I put the code that you wrote? I have buttons and such made in xml graphics files, and they have been given ids that are present in the R.id.name
Also another question, in the code you write you write "final Button Buttonname=(Button) findViewById(R.id.buttonID);"
What does the "final" mean and do?
Code:
package xxxx.xxxx.hello;
import android.app.Activity;
import android.os.Bundle;
public class HelloAndroid extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstances) {
super.onCreate(savedInstances);
setContentView(R.layout.main);
}
}
Bookmarks