如何在TextView tv上显示按钮b1上点击事件后3个编辑文本,et1,et2,et3的连接值?
我写了这段代码......
onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
b1=(Button)findViewById(R.id.b1);
tv=(TextView)findViewById(R.id.tv4);
et1=(EditText)findViewById(R.id.et1);
et2=(EditText)findViewById(R.id.et2);
et3=(EditText)findViewById(R.id.et3);
b1.setOnClickListener(new View.OnClickListener(){
public void onClick(View v){
String name,age,contact;
name=et1.getText().toString();
tv.setText(name);
age=et2.getText().toString();
tv.setText(age);
contact=et3.getText().toString();
tv.setText(contact);
}
});
答案 0 :(得分:2)
您可以尝试这样
b1.setOnClickListener(new View.OnClickListener(){
public void onClick(View v){
String name,age,contact;
name=et1.getText().toString();
age=et2.getText().toString();
contact=et3.getText().toString();
tv.setText(name + " "+ age + " "+contact);
}
});
输出:Upendra 25 9876543210
答案 1 :(得分:1)
问题评论中Divyesh Patel的解决方案:
b1.setOnClickListener(new View.OnClickListener(){
public void onClick(View v){
String name,age,contact;
name=et1.getText().toString();
age=et2.getText().toString();
contact=et3.getText().toString();
tv.setText(name+age+contact);
}
});