【发布时间】:2020-05-18 10:31:45
【问题描述】:
我最近创建了一个具有文本视图和编辑文本的类。 我正在使用编辑文本来获取用户的一些输入,并且我希望我的文本视图显示用户输入的内容。 我需要提到我的标签是动态创建的,我不知道如何引用它们。 C0你能给我一个线索吗?
public TextView itemName(Context context){
final ViewGroup.LayoutParams lparams = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
final TextView itemName = new EditText(context);
itemName.setLayoutParams(lparams);
return itemName;
}
public EditText desiredQuantity(Context context) {
final ViewGroup.LayoutParams lparams = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
final EditText desiredQuantity = new EditText(context);
desiredQuantity.setLayoutParams(lparams);
desiredQuantity.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
itemName.setText(desiredQuantity.getText().toString());
}
@Override
public void afterTextChanged(Editable s) {
}
});
return desiredQuantity;
}
【问题讨论】:
-
只需将 settext 放入
onTextChanged -
请直接在您的问题中显示代码,而不是屏幕截图。这将有助于我们更好地回答您的问题并分析代码。以此为例:meta.stackexchange.com/help/formatting