EditText继承于TextView,且Edittext不属于Layout,无法加入其它视图View,但是却可以将Textview的内容赋予EditText。以下是代码:
EditText editText = (EditText) findViewById(R.id.editText);
TextView textView = (TextView) findViewById(R.id.textView);
editText.setText(textView .getText());
实现了将editText的内容赋予了textView,但是这样做是完全没必要的,EditText和TextView是父类和子类的关系,建议可以尝试扩充EditText的功能来达到想要的结果。
您好,很高兴能帮助您
public class MainActivity extends Activity implements View.OnClickListener {
private EditText editText;
private TextView textView;
public void onCreate(Bundle saveInstanceState) {
super.onCreate(saveInstanceState);
findViewById(R.id.button).setOnClickListener(this);
editText = (EditText) findViewById(R.id.editText);
textView = (TextView) findViewById(R.id.textView);
}
public void onClick(View v) {
textView.setText(editText.getText()); // !
}
}
布局只要EditText和TextView还有一个Button就行了。
你的采纳是我前进的动力,
记得好评和采纳,答题不易,互相帮助,