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

Android使用清除按鈕清除所有EditText字段

Android Clearing all EditText Fields with Clear Button(Android使用清除按鈕清除所有EditText字段)
本文介紹了Android使用清除按鈕清除所有EditText字段的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

如何使用 Clear Button 清除布局中的所有 EditText 字段.我有一個注冊活動,它有大約 10 個不同的 EditTexts.我知道我可以去獲取每個具體的引用,然后 set.Text("");但我正在尋找一種更有活力的優雅方式.可能抓取 Layout 并遍歷其中的所有項目以查找 EditText 類型,然后將它們設置為 "".不知道如何做到這一點,并嘗試在網上搜索它,但沒有運氣.有示例代碼嗎?

How do I clear all the EditText fields in a layout with a Clear Button. I have a registration Activity that has about 10 different EditTexts. I know I could go and grab a reference to each specifically and then set.Text(""); But I am looking for a more dynamic elegant way. Possibly grab the Layout and loop through all the items in there looking for EditText types and then setting those to "". Not sure how to do that though and tried searching on the web for it but no luck. Any sample code?

推薦答案

@Pixie 的回答很棒,但我想讓它變得更好.

The answer by @Pixie is great but I would like to make it much better.

僅當所有 EditText 都在一個(一個)布局中時,此方法才能正常工作,但當有一堆嵌套布局時,此代碼不會處理它們.

This method works fine only if all the EditText are in a single(one) layout but when there are bunch of nested layouts this code doesn't deal with them.

在摸索了一會兒后,我提出了以下解決方案:

After scratching my head a while I've made following solution:

private void clearForm(ViewGroup group) {       
    for (int i = 0, count = group.getChildCount(); i < count; ++i) {
        View view = group.getChildAt(i);
        if (view instanceof EditText) {
            ((EditText)view).setText("");
        }

        if(view instanceof ViewGroup && (((ViewGroup)view).getChildCount() > 0))
            clearForm((ViewGroup)view);
    }
}

要使用此方法,只需按以下方式調用它:

To use this method just call this in following fashion:

clearForm((ViewGroup) findViewById(R.id.sign_up));

您可以在其中將您的 R.id.sign_up 替換為您的 XML 文件的根布局的 id.

Where you can replace your R.id.sign_up with the id of root layout of your XML file.

我希望這能幫助很多像我一樣的人.

I hope this would help many people as like me.

:)

這篇關于Android使用清除按鈕清除所有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 中的數值?)
主站蜘蛛池模板: 亚洲欧美在线观看 | 日韩欧美一级 | 国产精品高清一区二区三区 | 成人精品鲁一区一区二区 | 在线看黄免费 | 国产色网| 国产成人一区二区 | 日日噜噜噜夜夜爽爽狠狠视频, | 精品视频在线一区 | 一级在线免费观看 | 欧美在线观看一区 | 欧美国产亚洲一区二区 | 99久久婷婷国产综合精品首页 | 亚洲福利视频一区二区 | 成人午夜 | www.4虎影院 国产999精品久久久影片官网 | 亚洲欧美网站 | 亚洲国产二区 | a爱视频 | 91视频在线 | 亚洲高清在线观看 | av一区二区三区四区 | 久久一区二区三区电影 | 亚洲欧美精 | 一级黄色毛片免费 | 日本精品视频一区二区 | 久久久国产一区二区三区 | 日韩视频一区二区 | 久久久久成人精品 | 嫩草黄色影院 | 一级午夜aaa免费看三区 | 91久久久久久久久久久久久 | 国产精品美女在线观看 | 中文字幕视频在线免费 | 在线色网 | 亚洲视频一区在线观看 | 日韩毛片在线视频 | 国产美女特级嫩嫩嫩bbb片 | 国产成人精品a视频 | 在线中文字幕视频 | 国产精品一区二区在线 |