Issue
I'm very new to Android Developing (and stackoverflow).
I am trying to make an application that adds the URL of the website your currenty browsing into a spinner. The problem is simply that I don't know how to do this. I can't seem to find any way or solution to this, even tho I have been searching for a long time.
My code looks like this:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_browse);
WebView myWebView = (WebView) findViewById(R.id.webView1);
myWebView.setWebViewClient(new WebViewClient());
myWebView.loadUrl("no.wikipedia.org/wiki/Spesial:Tilfeldig");
}
[...]
btnAdd.setOnClickListener(new View.OnClickListener() {
public void onClick(View arg0) {
String label = inputLabel.getText().toString();
if (label.trim().length() > 0) {
// database handler
DatabaseHandler db = new DatabaseHandler(
getApplicationContext());
// inserting new label into database
db.insertLabel(label);
// making input filed text to blank
inputLabel.setText("");
// Hiding the keyboard
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(inputLabel.getWindowToken(), 0);
// loading spinner with newly added data
loadSpinnerData();
} else {
Toast.makeText(getApplicationContext(), "Please enter label name",
Toast.LENGTH_SHORT).show();
}
}
}
I would deeply appreciate any help.
Solution
Android's WebView
class has a getUrl()
method that you can use. It returns a String
that you can add to the adapter for your Spinner
.
There's a Spinner
tutorial here that goes over the details.
Answered By - acj
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.