久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

在 EditText 上設置焦點

Set Focus on EditText(在 EditText 上設置焦點)
本文介紹了在 EditText 上設置焦點的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我有一個 EditText-Field 并為其設置了 OnFocusChangeListener.當它失去焦點時,會調用一個方法,該方法將 EditText 的值與數據庫中的一個進行檢查.如果該方法的返回值為 true,則會顯示一個 toast,并且焦點應該再次回到 EditText 上.焦點應該總是回到 EditText 并且鍵盤應該顯示,直到方法的返回值為 false.

I have an EditText-Field and set an OnFocusChangeListener for it. When it has lost focus, a method is called, which checks the value of the EditText with one in the database. If the return-value of the method is true, a toast is shown and the focus should get back on the EditText again. The focus should always get back on the EditText and the keyboard should show, until the return-value of the method is false.

我想,我的真正問題還沒有完全清楚:屏幕上沒有其他項目應該能夠編輯,直到 EditText 的值被編輯為一個值,這使得方法checkLiganame(liganame)" 返回 false.只有 EditText-Field 應該是可編輯的.

I think, I haven't made my real problem perfectly clear yet: No other Item on the Screen should be able to edit, until the value of the EditText is edited to a value, which makes the method "checkLiganame(liganame)" return false. Only the EditText-Field should be editable.

這是我的代碼(對我不起作用):

here is my code (which doesn't work for me):

final EditText Liganame = (EditText) findViewById(R.id.liganame);

    Liganame.setOnFocusChangeListener(new OnFocusChangeListener() {

        @Override
        public void onFocusChange(View v, boolean hasFocus) {
            if (!hasFocus) {

                String liganame = Liganame.getText().toString();


                if (checkLiganame(liganame)) {
                    Toast toast = Toast.makeText(CreateTableActivity.this,
                            "Dieser Liganame ist bereits vergeben",
                            Toast.LENGTH_SHORT);
                    toast.show();
                    Liganame.requestFocus();
                }
            }

以及方法:

public boolean checkLiganame(String liganame) {
    boolean found = false;

    DatabaseHelper databaseHelper = new DatabaseHelper(this);
    SQLiteDatabase db = databaseHelper.getReadableDatabase();

    Cursor cursor = db.query("liga", new String[] { "liganame" },
            "liganame = '" + liganame + "'", null, null, null, null);
    Log.i("Liganame: ", String.valueOf(cursor));

    db.close();
    if (cursor != null) {
        found = true;
    }

    return found;
}

這段代碼導致如下結果:EditText失去焦點后,焦點跳回EditText,但我不能再編輯文本了.

This code leads to the following result: After the EditText has lost focus, the focus jumps back to EditText, but I can't edit the text anymore.

更改了我的代碼.場景:

Changed my code. Scenario:

我單擊第一個 EditText 并將一個字符串放入其中,該字符串已在數據庫中.吐司正在展示.現在我不能再編輯我的字符串了.我單擊鍵盤上的下一步",焦點停留在第一個 EditText 上.我嘗試編輯我的字符串,但沒有任何反應.相反,我的新字符串顯示在第二個 EditText 中.我單擊設備的后退箭頭,然后重新單擊第一個和第二個 EditText --> 沒有顯示鍵盤.

I click on the first EditText and put a String in it, which is already in the database. The toast is showing. Now I can't edit my String anymore. I click "next" on the keyboard and the focus stays on the first EditText. I try to edit my String, but nothing happens. Instead my new String is showing in the second EditText. I click on the back-arrow of my device and reclick on the first and second EditText --> no keyboard is showing.

這是我的新代碼:

public class CreateTableActivity extends Activity implements
    OnFocusChangeListener {

private EditText Liganame, Mannschaftsanzahl;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.create_league);

    Liganame = (EditText) findViewById(R.id.liganame);
    Liganame.setOnFocusChangeListener(this);
    Mannschaftsanzahl = (EditText) findViewById(R.id.mannschaftsanzahl);
    Mannschaftsanzahl.setOnFocusChangeListener(this);

    final Button save_button = (Button) findViewById(R.id.create_tabelle_speichern_button);

    OnClickListener mCorkyListener = new OnClickListener() {
        public void onClick(View v) {
            ButtonClick();
        }
    };
    save_button.setOnClickListener(mCorkyListener);



}

@Override
public void onFocusChange(View v, boolean hasFocus) {
    String liganame = Liganame.getText().toString();

    if (checkLiganame(liganame)) {
        if (Liganame.requestFocus()) {
            getWindow()
                    .setSoftInputMode(
                            WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
            Mannschaftsanzahl.clearFocus();
            Toast.makeText(CreateTableActivity.this,
                    "Dieser Liganame ist bereits vergeben",
                    Toast.LENGTH_SHORT).show();
        }
    }
}

推薦答案

只要把這一行放在你的 onCreate()

Just put this line on your onCreate()

editText.requestFocus();

這篇關于在 EditText 上設置焦點的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

EditText: Disable Paste/Replace menu pop-up on Text Selection Handler click event(EditText:禁用文本選擇處理程序單擊事件上的粘貼/替換菜單彈出)
Multiline EditText with Done SoftInput Action Label on 2.3(2.3 上帶有完成 SoftInput 操作標簽的多行 EditText)
How to detect the swipe left or Right in Android?(如何在 Android 中檢測向左或向右滑動?)
Prevent dialog dismissal on screen rotation in Android(防止在Android中的屏幕旋轉對話框解除)
How do I handle ImeOptions#39; done button click?(如何處理 ImeOptions 的完成按鈕點擊?)
How do you set EditText to only accept numeric values in Android?(您如何將 EditText 設置為僅接受 Android 中的數值?)
主站蜘蛛池模板: 欧美在线观看一区 | 激情欧美一区二区三区 | 免费在线观看黄色av | 99热这里 | 久久久久99 | 精品视频一区二区 | 午夜免费视频 | 欧美一级大黄 | 黄色大片免费播放 | 中文字幕在线观看一区 | 亚洲成人午夜在线 | 亚洲精品一区二区网址 | 国产精品久久久久无码av | 久久99深爱久久99精品 | 欧美美女被c| 九九九色| 久久爱黑人激情av摘花 | 免费一级黄色 | 日韩中文字幕久久 | av网站免费在线观看 | 亚洲综合日韩精品欧美综合区 | av免费网址 | 很黄很污的网站 | 日韩亚洲视频 | 日韩一区二区三区在线观看 | 午夜在线视频一区二区三区 | 午夜精品影院 | 久久久久久国产精品免费 | 日韩手机在线看片 | 亚洲国产成人av好男人在线观看 | 精品国产视频 | 草久视频 | www.青娱乐| 日韩在线免费视频 | 韩国av一区二区 | 欧美性猛交一区二区三区精品 | 久久久久久久久久久久一区二区 | 天天爱天天操 | 午夜精品视频 | 精品一区二区三区在线观看国产 | 欧美日韩国产在线观看 |