layout.xml file has button, I can't figure out how to link each button to open a new preference screen
layout.xml file has button, I can't figure out how to link each button to open a new preference screen.
looking to rearrange my app, currently it's all preference screen, w开发者_如何学编程antedto change it to revamp the UI a little to have buttons on the main page, and each one will open a new preference screen that I already have set up, any advice, I can't seem to figure out how to have it just open that already made preference scree.
For something like going to another screen from a home screen, i'll do somethingl ike this:
ImageView floor = (ImageView)findViewById(R.id.floor);
floor.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
Intent intent = new Intent(Home.this, WheelDemo.class);
startActivity(intent);
}
});
floor is a button image, it starts the new activity, WheelDemo when it is clicked on and goes to a new screen for that activity. Jut make sure each activity is registered in your manifest.
First, how to get some Java code executed when you click on a button:
- in layout xml file, add
android:onClick="onSomethingDescriptiveClick"
- in your activity, add a method
public void onSomethingDescriptiveClick(View caller) {}
This method will be executed, when you click on a button in running app. Replace SomethingDescriptive
with, uh, something descriptive. For example, if your button says "Preferences", the callback method could be onPreferencesClick
.
Next, consult this to see how to start a new activity: http://developer.android.com/guide/topics/fundamentals/activities.html#StartingAnActivity
I used a normal EditTextPreference but handled onPreferenceClick to cancel the dialog and catch the click.
mbtnCheckUpdate.setText ("Check Updates.");
mbtnCheckUpdate.setOnPreferenceClickListener( new OnPreferenceClickListener()
{
@Override
public boolean onPreferenceClick(Preference arg0)
{
((EditTextPreference)arg0).getDialog().cancel();
return true;
}
}
);
精彩评论