gpt4 book ai didi

android - 在自定义对话框中设置 TextView

转载 作者:塔克拉玛干 更新时间:2023-11-02 22:46:33 25 4
gpt4 key购买 nike

我已经创建了一个自定义对话框,但我无法将文本设置到 java 对话框布局中的 TextView 中,我的程序崩溃了。我的错误是什么?

public class Total_CBC extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);
setContentView(R.layout.total_cbc);
final TextView RBC_T = (TextView) findViewById(R.id.total_cbc_text_rbc);

Button RBC_B = (Button) findViewById(R.id.total_cbc_btn_rbc);

//

RBC_B.setOnClickListener(new OnClickListener() {

@Override
public void onClick(View arg0) {
showCustomDialog(RBC_T);
}
});
}


protected void showCustomDialog(final TextView _RBC_T) {
final Dialog dialog = new Dialog(Total_CBC.this);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.setContentView(R.layout.dialog_edit);
final EditText editText = (EditText) dialog.findViewById(R.id.dialog_edit_edittext);
Button button = (Button) dialog.findViewById(R.id.dialog_edit_btn);
TextView titel = (TextView) findViewById(R.id.dialog_edit_text_title);
titel.setText("RBC");
button.setOnClickListener(new View.OnClickListener() {

@Override
public void onClick(View v) {
_RBC_T.setText(editText.getText().toString());
dialog.dismiss();
}
});
dialog.show();
}

} 当我删除这行程序时,我需要设置文本

titel.setText("RBC");

最佳答案

改变

 TextView titel = (TextView) findViewById(R.id.dialog_edit_text_title);

 TextView titel = (TextView) dialog.findViewById(R.id.dialog_edit_text_title);

关于android - 在自定义对话框中设置 TextView ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19350430/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com