Hi,
I'm trying to make a small app showing some web pages with lunch menus from different restaurants. The thought is to use a Spinner to choose which restaurant your interested in and then todays menu, as a webpage, is shown below the spinner. However, I can't seem to manage to read from the Spinner which restaurant is chosen.
Here is my code.
I'm trying to make a small app showing some web pages with lunch menus from different restaurants. The thought is to use a Spinner to choose which restaurant your interested in and then todays menu, as a webpage, is shown below the spinner. However, I can't seem to manage to read from the Spinner which restaurant is chosen.
Here is my code.
Code:
package m.foods;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.webkit.WebView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.Spinner;
import android.widget.TextView;
public class Foods extends Activity {
Spinner localSpinner;
TextView text1;
Button button1;
WebView webview;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
localSpinner = (Spinner)findViewById(R.id.localSpinner);
text1 = (TextView)findViewById(R.id.text1);
button1 = (Button)findViewById(R.id.button1);
webview = (WebView)findViewById(R.id.webview1);
ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this,
R.array.restaurants, R.layout.my_normal_spinner_item_style);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
localSpinner.setAdapter(adapter);
button1.setOnClickListener(new clicker());
}
class clicker implements Button.OnClickListener
{
public void onClick(View v) {
String s = localSpinner.getSelectedItem().toString();
text1.setText(s);
if(s == "Chili & Lime")
webview.loadUrl("http://a.se");
else if(s == "JB")
webview.loadUrl("http://b.se");
else
webview.loadUrl("http://c.se");
}
}
}
Code:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">Mj