![](/img/trans.png)
[英]Cut text and add ellipses when TextView is overlapping another TextView
[英]How to add a textview when typing in another textview?
我有一組編輯文本,編輯文本的數量取決於用戶將輸入的步驟數。
我想要實現的是在初始時顯示一個edittext,然后當用戶輸入當前edittext時,它會在下面添加一個新的空白edittext。 我應該如何實現這個監聽器?
我考慮使用 textwatcher,它會監聽它改變的每個字符,但我只需要監聽第一個字符。
如果 charSequence 長度與您的值相對應,那么 EditText 動態如何?
在那里,您將在第一次編輯時使用 textWatcher
public void afterTextChanged(Editable s) {
}
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
if ((after == 1) && (count== 0) && start == 0))
//Implement a new EditText dynamically
}
public void onTextChanged(CharSequence s, int start, int before, int count) {
}
正如這里所解釋的; TextWatcher 的 onTextChanged、beforeTextChanged 和 afterTextChanged 之間的差異
start 是文本的起始索引
count 是修改前的文本長度
after 是修改后的文本長度
editText.addTextChangedListener(new TextWatcher() {
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
if(s.length == 0){
// This means user has erased all the text from the edittext.
// For this instance you have to remove the added edittext.
}
}
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
if(s.length == 0){
// It means your this was your initial input before changing text
// add another edit text at this moment.
}
}
@Override
public void afterTextChanged(Editable s) {
// TODO Auto-generated method stub
}
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.