要实现将从对话框中选择的选项显示在另一个布局中,可以按照以下步骤进行:
<TextView
android:id="@+id/selectedOptionTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("选择选项")
.setItems(optionsArray, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
String selectedOption = optionsArray[which]; // 获取所选内容
// 在这里进行下一步操作,将所选内容显示在另一个布局中
}
});
AlertDialog dialog = builder.create();
dialog.show();
TextView selectedOptionTextView = findViewById(R.id.selectedOptionTextView);
selectedOptionTextView.setText(selectedOption);
这样,在对话框中选择的选项的内容就会显示在另一个布局中的文本视图中了。
针对该问题,腾讯云提供的产品和服务如下:
移动开发服务介绍:https://cloud.tencent.com/product/mp 云数据库产品介绍:https://cloud.tencent.com/product/tcb 云函数产品介绍:https://cloud.tencent.com/product/scf
领取专属 10元无门槛券
手把手带您无忧上云