gpt4 book ai didi

java - Android Studio,如何动态更改对话框中的 View ,案例 : Retrofit onSuccess

转载 作者:行者123 更新时间:2023-12-02 09:57:38 25 4
gpt4 key购买 nike

通过使用改造作为 REST 客户端,

private void doGetRestBagLotNumber(int bagNumber, String lotNumber, final BagLotNumberRestService callback) {
Call<BagLotNumberModel> call = bagLotNumberRestService.getAntamBagLotNumber(bagNumber, lotNumber);
call.enqueue(new Callback<BagLotNumberModel>() {
@Override
public void onResponse(Call<BagLotNumberModel> call, Response<BagLotNumberModel> response) {

if (response.code() == 404 || response.code() == 422) {
Toast.makeText(getApplicationContext(), response.message(), Toast.LENGTH_SHORT).show();
} else {
int id = response.body().getId();
int bagNumber = response.body().getBagNumber();
String lotNumber = response.body().getLotNumber();

// Adding the response to recylerview
preparedObjectDataBagLotNumber(id, bagNumber, lotNumber);
callback.onSuccess(response.body() != null);
}
}

@Override
public void onFailure(Call<BagLotNumberModel> call, Throwable t) {
Toast.makeText(getApplicationContext(), t.getMessage(), Toast.LENGTH_SHORT).show();
}
});

}

我有一种方法来显示包含多个编辑文本的对话框从用户输入数据。

这是代码。

private void addItemTextMethod() {
// get prompts.xml view
LayoutInflater li = LayoutInflater.from(context);
View promptsView = li.inflate(R.layout.prompts_antam_incoming, null);

AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(context);

// set prompts.xml to alertDialog builder
alertDialogBuilder.setView(promptsView);

final EditText bagNumber = (EditText) promptsView.findViewById(R.id.editTextDialogAntamBagNumber);
final EditText lotNumber = (EditText) promptsView.findViewById(R.id.editTextDialogLotNumber);

// set dialog message
alertDialogBuilder
.setCancelable(false)
.setPositiveButton("Search", null)
.setNegativeButton("Cancel",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.cancel();
}
});

// create alert dialog
AlertDialog alertDialog = alertDialogBuilder.create();
alertDialog.setOnShowListener(new DialogInterface.OnShowListener() {

@Override
public void onShow(DialogInterface dialogInterface) {
Button button = ((AlertDialog) alertDialog).getButton(AlertDialog.BUTTON_POSITIVE);
button.setOnClickListener(view -> {
doGetRestBagLotNumber(
Integer.parseInt(bagNumber.getText().toString()), lotNumber.getText().toString(),
new BagLotNumberRestService() {
@Override
public void onSuccess(boolean value) {
if($value){

// The question is here
// Show Big Thick in center of dialog

// Show bottom option, Close or Adding More

// If user choose Adding More , display this dialog again
}
}
@Override
public Call<BagLotNumberModel> getAntamBagLotNumber(int bagNumber, String lotNumber) {
return null;
}
}

);
});
}
});
alertDialog.show();
}

当 doGetRestBagLotNumber 回调结果为 true 时,如何处理应用程序显示如下选项:

  1. 在对话框中央显示 Big Thick 作为成功消息
  2. 显示底部选项、关闭或添加更多。
  3. 如果用户选择“添加更多”,则再次显示此对话框

非常感谢任何帮助

最佳答案

使用膨胀 View 的实例来更改其中的 subview 。例如,在 onSuccess 方法中使用它:

((ImageView)promptsView.findViewById(R.id.tickIndicationView)).setImageResource(R.drawable.ic_tick);

关于java - Android Studio,如何动态更改对话框中的 View ,案例 : Retrofit onSuccess,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55878269/

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