I have a fairly basic page which contains several buttons external websites which I want to be launched in the browser. What I am not sure is exactly how I should store the URL of the pages.
I am quite new to Android, so if I am taking the wrong approach please guide me.
I have several buttons like so:
<Button
style="?android:attr/buttonBarButtonStyle"
android:onClick="openUrlFromButton"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_weight=".3"
android:gravity="center_horizontal"
android:id="@+id/btn_contact_page"
android:text="@string/contact_page" />
My callback is like so:
public void openUrlFromButton(View view){
Uri uriUrl;
switch(view.getId()){
case R.id.btn_contact_facebook:
uriUrl = Uri.parse("http://google.com/");
default:
uriUrl = Uri.parse("http://stackoverflow.com/");
}
Intent launchBrowser = new Intent(Intent.ACTION_VIEW, uriUrl);
startActivity(launchBrowser);
}
What I am unsure about, is how would be best to store the URL.
I'd like to be able to directly reference it in the same format as the ID used to access the button (i.e., from the view), or at least a consistent way that isnt hard coded in the callback (store it in the XML defining the button directly).
Can anyone point me to a proper way of achieving this?
Many thanks