我需要通過從編輯文本中獲取值來設置按鈕的文本,單擊按鈕時,必須將其文本更改爲Edittext中指定的文本。如何在android中點擊一個按鈕來更改文本?
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final Button btn=(Button)findViewById(R.id.button);
assert btn != null;
btn.setOnClickListener(
new View.OnClickListener(){
public void onClick(View v)
{
TextView txt=(TextView)findViewById(R.id.editText);
btn.setText((CharSequence) txt);
}
}
);
}
這種 「文字」 你所談論的是什麼格式?標籤或文本字段中? – progyammer
如果能幫助解決問題,請[接受答案](http://meta.stackexchange.com/a/5235/155831)。 –