Apparently having some issues with my Key-Value the way it is currently set up. The goal is to read the value of a Spinner (set using a string array) and then based on it open up a specific local html file.
public class MainActivity extends Activity {
private Button btnGo;
String pageChoice;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final Spinner page = (Spinner)findViewById(R.id.txtPage);
final SharedPreferences sharedPref =PreferenceManager.getDefaultSharedPreferences(this);
btnGo = (Button)findViewById(R.id.btnGo);
btnGo.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
pageChoice = page.getSelectedItem().toString();
//Hopefully will allow for "global" url setting.
SharedPreferences.Editor editor = sharedPref.edit();
editor.putString("key1", pageChoice);
editor.commit();
startActivity(new Intent(MainActivity.this, Web.class));
}
});
}
}
The error is located in my Web.java.
public class Web extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.web);
SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(this);
String strPage = sharedPref.getString(key1, "");
if (strPage = "By The Numbers") {
//WebView
WebView wv = (WebView) findViewById(R.id.webview1);
WebSettings webSettings = wv.getSettings();
webSettings.setBuiltInZoomControls(true);
wv.loadUrl("file:///android_asset/2.html");
} else if (strPage = "Photos") {
//WebView
WebView wv = (WebView) findViewById(R.id.webview1);
WebSettings webSettings = wv.getSettings();
webSettings.setBuiltInZoomControls(true);
wv.loadUrl("file:///android_asset/3.html");
}
}
@Override
public void onBackPressed() {
// TODO Auto-generated method stub
super.onBackPressed();
}
}
Also, is there an issue with my strPage being a String? How would I change it over to working with an If/Else instance?