Note that there are some explanatory texts on larger screens.

plurals
  1. PO1)Difference between setOnClickListener and onclick 2) how to only reload webview w/o reloading others in the same linearlayout
    primarykey
    data
    text
    <p>My application has a WebView on top. For showing things, I use Toast. But the Toast box has never shown if WebView appears, while before WebView shows, Toast is visible. I was wondering if Toast was likely covered by WebView. Did anyone have the same problems?</p> <p>Thanks.</p> <p>EDITING!!! Hi, thank you for all your inputs. I found I posted a wrong question for my problems. I found that the real problems are the following. In the code, I use setOnClickListener to register a callback for the button. In debugging, I found that the callback is not called for some reason, so the Toast statement is not called, and it is not covered by webview.</p> <p>Then, I tried the onclick attributes in xml layout for defining a callback clickGo for the button. This one works when I press the button, and the Toast shows.</p> <p>Now, my question is what is the difference between setOnClickListener and onlick.</p> <p>One more question, in my clickGo, I refresh the webview. The webview indeed reloads when button is clicked. But in the meanwhile the spinner is also reloaded, and the selection position is reset to the 0-th. How can I prevent this?</p> <p>Thank you again!</p> <pre><code> public class MainActivity extends Activity { JSONArray jArray; String result = null; InputStream is = null; StringBuilder sb=null; private Spinner spinner; private Button btnSubmit; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); addListenerOnButton(); addListenerOnSpinnerItemSelection(); new DownloadTask().execute("www.google.com"); } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.main, menu); return true; } // Given a string representation of a URL, sets up a connection and gets // an input stream. private String downloadUrl(String urlString) throws IOException { HttpClient httpClient = new DefaultHttpClient(); HttpGet get = new HttpGet(urlString); HttpResponse response = httpClient.execute(get); // Build up result return EntityUtils.toString(response.getEntity()); } public void addListenerOnSpinnerItemSelection() { spinner = (Spinner) findViewById(R.id.spinner); spinner.setOnItemSelectedListener(new CustomOnItemSelectedListener()); } public void clickGo(View v) { Toast toast = Toast.makeText(MainActivity.this, "OnClickListener : " + "\nSpinner 1 : "+ String.valueOf(spinner.getSelectedItem()), Toast.LENGTH_SHORT); toast.setGravity(Gravity.TOP, 0, 0); toast.show(); new DownloadTask().execute("www.google.com"); } // get the selected dropdown list value public void addListenerOnButton() { spinner = (Spinner) findViewById(R.id.spinner); btnSubmit = (Button) findViewById(R.id.button); btnSubmit.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { Toast toast = Toast.makeText(MainActivity.this, "OnClickListener : " + "\nSpinner 1 : "+ String.valueOf(spinner.getSelectedItem()), Toast.LENGTH_SHORT); toast.setGravity(Gravity.TOP, 0, 0); toast.show(); new DownloadTask().execute("www.google.com"); } }); } ` // Implementation of AsyncTask used to download XML feed from stackoverflow.com. private class DownloadTask extends AsyncTask&lt;String, Void, String&gt; { @Override protected String doInBackground(String... urls) { return downloadUrl(urls[0]); } @Override protected void onPostExecute(String result) { setContentView(R.layout.activity_main); // Displays the HTML string in the UI via a WebView WebView myWebView = (WebView) findViewById(R.id.webview); WebSettings webSettings = myWebView.getSettings(); webSettings.setJavaScriptEnabled(true); myWebView.loadUrl(result); } } } &lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" &gt; &lt;LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal" &gt; &lt;TextView android:id="@+id/text" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/word" /&gt; &lt;Button android:id="@+id/button" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Go" android:onClick="clickGo" /&gt; &lt;/LinearLayout&gt; &lt;Spinner android:id="@+id/spinner" android:layout_width="match_parent" android:layout_height="wrap_content" android:entries="@array/dictionaries" android:prompt="@string/dict_prompt" /&gt; &lt;WebView android:id="@+id/webview" android:layout_width="fill_parent" android:layout_height="fill_parent" /&gt; &lt;/LinearLayout&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload