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

如何在代碼中獲取 EditText maxLength 設(shè)置

How to Get EditText maxLength setting in code(如何在代碼中獲取 EditText maxLength 設(shè)置)
本文介紹了如何在代碼中獲取 EditText maxLength 設(shè)置的處理方法,對大家解決問題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

問題描述

我希望在運(yùn)行時(shí)查看 EditTextmaxLength 以便能夠做出文本顯示決定.
這可能嗎?

I would like to see the maxLength of an EditText at run time to be able to make a text display decision.
Is that possible?

這是對我不想做的事情的描述.

Here is a description of what I wan't to do.

我有一個(gè)包含許多行的 ListView,每行都有一個(gè) EditText 和一個(gè) TextView.
我創(chuàng)建了一個(gè) ArrayAdapter 的子類,以便能夠提供我想要放置在每行的 EditText 中的字符串.
我在 XML 文件中設(shè)置了 android:maxLength="12".
我想在該 EditText 字段中顯示一個(gè)數(shù)字,但如果我想顯示的數(shù)字超過 android:maxLength="12" 我想顯示一條錯(cuò)誤消息".

I have a ListView with many rows and each row have an EditText and a TextView.
I've made a subclass of ArrayAdapter to be able to feed the String that I want to place in the EditText of each row.
I have set android:maxLength="12" in the XML file.
I want to display a number in that EditText field, but if the number I want to display has more than android:maxLength="12" I want to display an "error message" instead.

而且我不希望在我的 ArrayAdapter 子類中硬編碼這 12 個(gè).

And I would prefer not to hard code that 12 in my subclass of ArrayAdapter.

可能有一個(gè)簡單的解決方案,但我還沒有找到.
(安卓第一次……)

There is probably a simple solution, but I haven't found it yet.
(android first time...)

推薦答案

只有有限的參數(shù)才有g(shù)etter,所以我覺得你看不懂.

Only limited parameters have their getters, so I don't think you can read it .

所以在 values 文件夾中寫入長度(比如 12)并在 xml 布局和 arrayAdapter 中使用它.現(xiàn)在它不是硬編碼的.

So write length (Say 12) in values folder and use it in xml layout and arrayAdapter . Now its not hard-coded .

1) 在值中創(chuàng)建 integer.xml *

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <item type="integer" name="max_length">12</item>
</resources>

2)在布局中

<TextView  android:id="@+id/tv"
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content"
    android:maxLength="@integer/max_length"
    />

3) 在 ArrayAdapter 中:

int maxLength = getResources().getInteger(R.integer.max_length);

這篇關(guān)于如何在代碼中獲取 EditText maxLength 設(shè)置的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

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

相關(guān)文檔推薦

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 操作標(biāo)簽的多行 EditText)
How to detect the swipe left or Right in Android?(如何在 Android 中檢測向左或向右滑動(dòng)?)
Prevent dialog dismissal on screen rotation in Android(防止在Android中的屏幕旋轉(zhuǎn)對話框解除)
How do I handle ImeOptions#39; done button click?(如何處理 ImeOptions 的完成按鈕點(diǎn)擊?)
How do you set EditText to only accept numeric values in Android?(您如何將 EditText 設(shè)置為僅接受 Android 中的數(shù)值?)
主站蜘蛛池模板: 中文字幕在线精品 | 欧美久久久久 | 欧洲一区在线观看 | 国产小视频精品 | 天天干狠狠干 | 国产欧美一区二区在线观看 | 欧美成人精品一区二区男人看 | 看黄在线 | 亚洲成人av | 欧美成人激情 | 国产伦一区二区三区四区 | 日韩有码在线观看 | 欧美一级大片免费观看 | 亚洲久久一区 | 成人免费网站在线 | 欧美日韩中文字幕在线 | 一级毛片免费看 | 一二三四在线视频观看社区 | 欧美精品1区 | 天天操天天天干 | 亚洲国产精品91 | 一级毛片观看 | 日韩免费av| 亚洲一区二区国产 | 免费一区二区 | 久久国产美女视频 | 亚洲综合久久久 | 国产精品美女 | 中国美女av | 欧美一级片在线看 | 日本久久一区 | 中文字幕一区二区三区四区 | 天天插天天射天天干 | www.一区二区三区 | 日韩美女在线看免费观看 | 99热这里都是精品 | 国产精品不卡一区 | 欧美一级久久 | 五月花丁香婷婷 | 成人午夜在线观看 | 精产国产伦理一二三区 |