gpt4 book ai didi

java - Android获取文本EditText到AlertDialog

转载 作者:行者123 更新时间:2023-12-02 01:49:54 25 4
gpt4 key购买 nike

我必须从 AlertDialog 中获取文本。

对于 AlertDialog,我使用特定的布局:custom_alertdialog

对于所有项目使用:另一个布局

我尝试过这样的:

View layout = getLayoutInflater().Inflate(R.layout.custom_alertdialog,null);

或者这样:

View layout = View.inflate(SimpleVideoStream.this, R.layout.custom_alertdialog, null);

但是在这两种情况下都不会采用文本。我该怎么办?

AlertDialog.Builder builder = new AlertDialog.Builder(SimpleVideoStream.this);
builder.setTitle("Add Subtitle");
builder.setCancelable(true);

builder.setPositiveButton(
"Ok",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
View inflatedView = getLayoutInflater().inflate(R.layout.custom_alertdialog, null);
final View layout = View.inflate(SimpleVideoStream.this, R.layout.custom_alertdialog, null);

EditText url_ele = (EditText) layout.findViewById(R.id.url);
String sub = url_ele.getText().toString();
Log.v("Ok:","/"+sub);
if (!sub.equals("")) {
showSub = !showSub;
Format textFormat = Format.createTextSampleFormat(null, MimeTypes.APPLICATION_SUBRIP,
null, Format.NO_VALUE, Format.NO_VALUE, "en", null, Format.OFFSET_SAMPLE_RELATIVE);
MediaSource textMediaSource = new SingleSampleMediaSource.Factory(dataSourceFactory)
.createMediaSource(Uri.parse(sub), textFormat, C.TIME_UNSET);

videoSource = new MergingMediaSource(videoSource, textMediaSource);
player.prepare(videoSource, false, false);
}
dialog.cancel();
}
});

builder.setNegativeButton(
"Close",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.cancel();
}
});

AlertDialog alert = builder.create();
LayoutInflater inflater = getLayoutInflater();
View dialoglayout = inflater.inflate(R.layout.custom_alertdialog, null);
alert.setView(dialoglayout);
alert.show();

最佳答案

在您的 builder 实例中,您膨胀了一个布局(布局 A)。在 setView() 方法之前,您膨胀了另一个布局(布局B)。这两种布局是不同的。

你可以这样做:

AlertDialog.Builder builder = new AlertDialog.Builder(SimpleVideoStream.this);
LayoutInflater inflater = this.getLayoutInflater();
View dialogView= inflater.inflate(R.layout.custom_alertdialog, null);
builder.setView(inflater.inflate(R.layout.custom_alertdialog, null))
final EditText editText = (EditText)dialogView.findViewById(R.id.url);

builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int id) {
//Do something
}
}
});
.setNegativeButton(){
//Do something
};
builder.create();
builder.show();

关于java - Android获取文本EditText到AlertDialog,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53136428/

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