WebView Url Issue

Put your problem here if it does not fit any of the other categories.

WebView Url Issue

Postby droidarama » Fri Feb 03, 2012 5:39 pm

In my program I have a popup listView dialog that populates from an arrayList object, inside it is 3 fields, one of which holds the URL. When I click one of the list items I want it to get the url of that object and close the dialog and set it to my WebView class loadUrl(url), but I don't want the WebView activity to start at that moment, I just want the url information to be set in that activity.

Because I have a button in a menu behind the dialog that will start my webview activity upon click.


Can anyone help me?
Desperate for help

Thanks
droidarama
Freshman
Freshman
 
Posts: 9
Joined: Fri Feb 03, 2012 4:48 pm

Top

Re: WebView Url Issue

Postby Phyll » Fri Feb 03, 2012 7:47 pm

Hi droidarama,

You should keep the URL that you get from the selection and then pass it to the webview when they press the menu key. That seems like the way to do it if that's the sequence you want to do.

I'm guessing you don't know how to get it back from your dialog? Let me know if that's the case.

Hope this helps.

Phyll
Phyll
Master Developer
Master Developer
 
Posts: 648
Joined: Fri Oct 14, 2011 11:19 am

Re: WebView Url Issue

Postby droidarama » Sat Feb 04, 2012 12:02 pm

Well when they click a listitem in the dialog it was creating an intent to store the url and then send it to the webview class, but the only way it was working was if I started the activity with the intent upon click of the listitem. So whats the best way to get it back from my dialog?
droidarama
Freshman
Freshman
 
Posts: 9
Joined: Fri Feb 03, 2012 4:48 pm

Re: WebView Url Issue

Postby Phyll » Sat Feb 04, 2012 6:20 pm

Hi droidarama,

I guess I'm saying you should get the URL back from your dialog and then make the intent for the webview when you press the other button.

I don't know what kind of code you are using for your dialog. Are you using an alert dialog or an activity in the dialog style?

You should start that dialog with a startActivityForResult().

Then return your result (the URL or whatever the other two items are) in an intent with setResult(RESULT_OK,intent) before the finish().

You would receive the URL in an onActivityResult() and then store the user selection for use in the button onClick().

Hope this helps.

Phyll
Phyll
Master Developer
Master Developer
 
Posts: 648
Joined: Fri Oct 14, 2011 11:19 am

Re: WebView Url Issue

Postby droidarama » Sun Feb 05, 2012 7:36 pm

Yeah I'm using an alert Dialog
This is my listView click listener in the dialog at the moment

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. lv.setOnItemClickListener(new OnItemClickListener()
  2. {
  3.  
  4.         public void onItemClick(AdapterView<?> parent, View view, int position, long id)
  5.         {
  6.                 Object o = lv.getItemAtPosition(position);
  7.                 ClassWithUrlParameter fullObject = (ClassWithUrlParameter)o;
  8.                 Intent i = new Intent(HomeMenu.this, WebView.class);
  9.                 i.putExtra("url", fullObject.getUrl());
  10.                 startActivity(i);
  11.         }
  12.         });
Parsed in 0.032 seconds, using GeSHi 1.0.8.4


then in the WebView.class I have
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. String url = getIntent().getStringExtra("url");
  2. webview.loadUrl(url);
Parsed in 0.031 seconds, using GeSHi 1.0.8.4


and my button to start the webview looks like this

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. webviewbutton.setOnClickListener(new View.OnClickListener(){
  2.                        
  3.                 public void onClick(View v){
  4.                 Intent webViewIntent = new Intent(HomeMenu.this, WebView.class);
  5.                 startActivity(webViewIntent);  
  6.                 }});
Parsed in 0.034 seconds, using GeSHi 1.0.8.4


I'm not sure exactly what your saying with the startActvity etc, I've never touched on that. Could u show me with my code please?
droidarama
Freshman
Freshman
 
Posts: 9
Joined: Fri Feb 03, 2012 4:48 pm

Re: WebView Url Issue

Postby Phyll » Mon Feb 06, 2012 12:14 am

Hi droidarama,

Here is a project that uses an activity as a dialog. You can do about anything you want with that.

Hope this helps.

Phyll
Attachments
App9.zip
Selection Dialog Example
(41.52 KiB) Downloaded 16 times
Phyll
Master Developer
Master Developer
 
Posts: 648
Joined: Fri Oct 14, 2011 11:19 am

Top

Re: WebView Url Issue

Postby droidarama » Tue Feb 07, 2012 1:54 pm

Thank you
droidarama
Freshman
Freshman
 
Posts: 9
Joined: Fri Feb 03, 2012 4:48 pm

Top

Return to Other Coding-Problems

Who is online

Users browsing this forum: Google [Bot], Google Feedfetcher, MSNbot Media and 19 guests