我正在開發一個android應用程序。它使用的WebView加載一個形式如下組件:Webview提交表單當點擊「開始」按鈕
- 用戶名文本框
- 密碼文本框
- 提交按鈕
當我填寫所有字段,然後點擊提交按鈕,數據將被驗證,但是當我點擊Android鍵盤上的「Go」按鈕時,沒有任何反應。我如何解決它?
P/S:我正在調試Android 4.4.4設備。
我正在開發一個android應用程序。它使用的WebView加載一個形式如下組件:Webview提交表單當點擊「開始」按鈕
當我填寫所有字段,然後點擊提交按鈕,數據將被驗證,但是當我點擊Android鍵盤上的「Go」按鈕時,沒有任何反應。我如何解決它?
P/S:我正在調試Android 4.4.4設備。
For that you need to handle button click event
view.setOnEditorActionListener(new OnEditorActionListener() {
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
if ((event != null && (event.getKeyCode() == KeyEvent.KEYCODE_ENTER)) || (actionId == EditorInfo.IME_ACTION_DONE)) {
Log.i(TAG,"Enter pressed");
//do whatever you were doing in submit button
}
return false;
}
});
我無法在WebView中找到setOnEditorActionListener()方法。 – furyfish
它應該在視圖中包含webview –
我有webview不是android edittext。我可以找到辦法... –
你必須使用html表單和javascript來控制提交。在Go按鈕上單擊提交表單;
<form>
<input type='text' id='user_id' />
<input type='password' id='password' />
<input type='button' id='btn_login' />
</form>
<script>
function login()
{
// login code here
}
$('btn_login').click(function() {
login();
});
$('form').submit(function() {
// this event fire on go button click.
login();
return false;
});
</script>
你的日誌在哪裏?我看不到它 – Shahzeb
我認爲這段代碼將幫助android:singleLine =「true」 – Android
@SanjuChandran謝謝。但它仍然不起作用。 – furyfish