Java Can';t以编程方式更改android布局文件元素的值
我的android项目中有一个java类,它创建了我的自定义对话框。但是,当我想为自定义对话框布局文件设置文本或其他属性时,我不能 在我的活动或自定义对话框java类中使用setText更改对话框布局的textView时,不会发生任何更改 这是我的自定义对话框布局文件Java Can';t以编程方式更改android布局文件元素的值,java,android,android-layout,Java,Android,Android Layout,我的android项目中有一个java类,它创建了我的自定义对话框。但是,当我想为自定义对话框布局文件设置文本或其他属性时,我不能 在我的活动或自定义对话框java类中使用setText更改对话框布局的textView时,不会发生任何更改 这是我的自定义对话框布局文件 <?xml version="1.0" encoding="utf-8"?> <android.support.constraint.ConstraintLayout xmlns:android="http://
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:background="@color/dark_primary"
android:layout_height="match_parent">
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="24dp"
android:layout_marginStart="24dp"
android:layout_marginTop="8dp"
android:text="@string/alert"
android:textSize="@dimen/alert_title_font_size"
android:textColor="@android:color/white"
android:fontFamily="@font/berlin_regular"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</android.support.constraint.ConstraintLayout>
在上述代码中
textView.setText(“测试”)代码>不起作用:它将不更改字段内容。我在xml(@string/alert)中设置的默认文本仍然显示 好的,查看您正在使用的库,我发现了这个.setContentHolder(新的ViewHolder(view))
因此,将代码从
DialogPlus dialog = DialogPlus.newDialog(this.context)
.setContentHolder(viewHolder)
.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(DialogPlus dialog, Object item, View view, int position) {
}
})
.setExpanded(true) // This will enable the expand feature, (similar to android L share dialog)
.create();
到
@GhostCat谢谢我编辑了我的主题检查这是否适合你dialog.setView(dialogView)。。在对话框之前添加此项。show@AdeelTurk我正在使用另一个库来构建此对话框,但它没有此方法(setView)。然后更改库源或编写自己的库,或者询问编写它的开发人员非常感谢您!它工作得很好。但是你能解释一下我将布局设置为dialog builder的方式和你这样做的方式有什么区别吗?!您没有将自定义视图传递给对话框。。因此,我在viewholder对象中传递了它,简称为new viewholder(dialogView)。这是这里的魔咒abra ka dabra Boom()这个链接帮助了我,所以你应该先阅读这里给出的git说明。。快乐编码
DialogPlus dialog = DialogPlus.newDialog(this.context)
.setContentHolder(viewHolder)
.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(DialogPlus dialog, Object item, View view, int position) {
}
})
.setExpanded(true) // This will enable the expand feature, (similar to android L share dialog)
.create();
DialogPlus dialog = DialogPlus.newDialog(this.context)
.setContentHolder(new ViewHolder(dialogView ))
.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(DialogPlus dialog, Object item, View view, int position) {
}
})
.setExpanded(true) // This will enable the expand feature, (similar to android L share dialog)
.create();