Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to focus on Webview upon selecting an EditText within same Layout in Android?
    primarykey
    data
    text
    <p>I have been trying to add EditTexts and WebView in a layout. The trouble is with focussing on WebView. I have tried to look through the answers on the web and Stackoverflow before deciding to ask one again. </p> <p>In the webview, I have some fields to fill in, which are sent via POST. If I select the Webview first (then enter the values in the field), it's fine. However, if I select the EditTexts first, I cannot focus on the Webview to fill in the fields on the webpage, although it seems that another cursor is setup in parallel to the one in the EditText section. The resulting webpage contains some information which I will require to add to the EditTexts.</p> <p>My code so far:</p> <pre><code>public class LoadWebandEditText extends Activity { @Override public void onCreate(Bundle savedInstanceState){ super.onCreate(savedInstanceState); setContentView(R.layout.oauth_signin); final WebView webpage = (WebView)findViewById(R.id.webview_page); webpage.setWebViewClient(new WebViewClient()); webpage.loadUrl("www.towardsmypage.com"); Button btn_next = (Button)findViewById(R.id.btn_next); final EditText edittext_1 = (EditText)findViewById(R.id.editText_1); final EditText edittext_2 = (EditText)findViewById(R.id.EditText_2); webpage.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { webpage.requestFocus(); webpage.setFocusable(true); } }); webpage.setOnFocusChangeListener(new OnFocusChangeListener(){ public void onFocusChange(View arg0, boolean hasFocus) { if (!hasFocus){ webpage.requestFocus(); webpage.setFocusable(true); } } }); </code></pre> <p>My Layout.xml:</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" &gt; &lt;WebView xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/webview_page" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_weight="0.7" android:focusable="true"/&gt; &lt;TextView android:id="@+id/TextView01" android:layout_width="wrap_content" android:layout_height="wrap_content" android:paddingLeft="15dip" android:text="Enter Field Information 1" android:textSize="18dp" android:textStyle="bold" android:typeface="sans" /&gt; &lt;EditText android:id="@+id/editText_1" android:layout_width="match_parent" android:layout_height="wrap_content" android:ems="10" android:inputType="textPassword" &gt; &lt;/EditText&gt; &lt;TextView android:id="@+id/textView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:paddingLeft="15dip" android:text="Enter Field Information 2" android:textSize="18dp" android:textStyle="bold" android:typeface="sans" /&gt; &lt;EditText android:id="@+id/EditText_2" android:layout_width="match_parent" android:layout_height="wrap_content" android:ems="10" android:inputType="textPassword" /&gt; &lt;Button android:id="@+id/btn_next" style="?android:attr/buttonStyleSmall" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Button" android:layout_gravity="center_horizontal" /&gt; &lt;/LinearLayout&gt; </code></pre>
    singulars
    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