本文介绍了我想在单击按钮时创建一个复选框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
I want to make it so every time someone type something in the editText and click the button the text comes up which it does it my code but I also want to add a checkbox next to it. How Can I add the checkbox every time the button is pressed.
I would also want to make it possible to add more than 1 right now it overwrites itself when you make 2.
final TextView textViewPrint;
Button btn_print;
final EditText editTextType;
final CheckBox checkbox;
textViewPrint = findViewById(R.id.print_text);
btn_print =findViewById(R.id.button_add);
editTextType = findViewById(R.id.test_textEdit);
checkbox = findViewById(R.id.checkBox);
btn_print.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
textViewPrint.setText(editTextType.getText().toString()) ;
editTextType.setText("");
}
});
我的尝试:
我试图在google / stack overflow上寻找答案。我是初学者所以我错过了很多基本的理解。
What I have tried:
I have tried looking for answers on google / stack overflow. I'm a beginner so I miss a lot of basic understandings.
推荐答案
LinearLayout l1 = (LinearLayout)findViewById(R.id.linearlayout);
btn_print.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
CheckBox checkbox = new CheckBox(this);
checkbox.setId(0);
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.WRAP_CONTENT);
l1.addView(checkbox,params);
}
});
这篇关于我想在单击按钮时创建一个复选框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!