gpt4 book ai didi

java - 在警报对话框中,我想显示所选值

转载 作者:行者123 更新时间:2023-12-01 10:29:48 28 4
gpt4 key购买 nike

public class QuotesFragment extends Fragment implements QuotesDataHelper.QuotesListener, QuotesAdapter.OnQuoteActionListener {

public static final String TAG = QuotesFragment.class.getSimpleName();

private Views mViews;
private QuotesDataHelper mDataHelper;
private Quote mSelectedQuote;

public QuotesFragment() {
// Required empty public constructor
}

/**
* Use this factory method to create a new instance of
* this fragment
*
* @return A new instance of fragment QuotesFragment.
*/
public static QuotesFragment newInstance() {
QuotesFragment fragment = new QuotesFragment();
return fragment;
}

@Override
public void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);
}

/**
* Retrieve the request for quotes data from service
*/
private void getQuotesData() {
showProgress(true);
mDataHelper.getQuotesDetails(LobbSharedPreferences.getFromSharedPreferences(getContext(), StringUtils.LOBB_SHARED_PREFERENCE_TRUCK_OWNER_ID));
}

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View rootView = inflater.inflate(R.layout.fragment_quotes_page, container, false);
mViews = new Views(rootView);
mDataHelper = new QuotesDataHelper(this);
getQuotesData();
return rootView;
}

@Override
public void onResume() {
super.onResume();
}

@Override
public void onAttach(Activity activity) {
super.onAttach(activity);
}

@Override
public void onDetach() {
super.onDetach();
}

/**
* Shows the progress UI and hides the dashboard.
*/
private void showProgress(final boolean show) {
mViews.mProgressView.setVisibility(show ? View.VISIBLE : View.GONE);
mViews.mQuotesView.setVisibility(show ? View.GONE : View.VISIBLE);
}

private void showNoDataView(String message) {
mViews.mNoDataView.setVisibility(View.VISIBLE);
mViews.mQuotesView.setVisibility(View.GONE);
mViews.mNoDataView.setText(message);
}

private void showToast(String message) {
Toast.makeText(getActivity(), message, Toast.LENGTH_LONG).show();
}

@Override
public void showQuotes(ArrayList<Quote> quotesList) {
showProgress(false);
if (quotesList != null && quotesList.size() > 0) {
mViews.mQuotesView.setHasFixedSize(true);
mViews.mQuotesView.addItemDecoration(new DividerItemDecoration(getActivity(), DividerItemDecoration.VERTICAL_LIST));
final LinearLayoutManager layoutManager = new LinearLayoutManager(getContext());
layoutManager.setOrientation(LinearLayoutManager.VERTICAL);
mViews.mQuotesView.setLayoutManager(layoutManager);
QuotesAdapter mAdapter = new QuotesAdapter(getContext(), quotesList);
mAdapter.setQuoteActionListener(this);
mViews.mQuotesView.setAdapter(mAdapter);
} else {
showNoDataView(getResources().getString(R.string.quotes_nodata));
}
}



@Override
public void showError(String title, String errorMessage) {
showProgress(false);
showNoDataView(errorMessage);
}

@Override
public void onQuoteIgnored() {
showProgress(false);
showToast(getResources().getString(R.string.quote_ignore_success));
//Quote ignored . So reload the data
getQuotesData();
}

@Override
public void onQuoteIgnoreFailed() {
showProgress(false);
if (!((Activity) getContext()).isFinishing()) {
new android.app.AlertDialog.Builder(getContext()).setTitle(getResources().getString(R.string.error_title)).setMessage(getResources().getString(R.string.error_ignore_quote)).setNeutralButton("OK", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
}).show();
}
}

@Override
public void onCreateQuoteSuccess() {
showProgress(false);
showToast(getResources().getString(R.string.quote_create_success));
//Quote created. So refresh
getQuotesData();
}

@Override
public void onCreateQuoteFailure() {
showProgress(false);
showToast(getResources().getString(R.string.quote_create_failure));
}

@Override
public void onQuote(Quote quote) {
mSelectedQuote = quote;
showConfirmationAlert();
}
private void showConfirmationAlert() {
AlertDialog.Builder builder = new AlertDialog.Builder(getContext());
builder.setMessage(getResources().getString(R.string.quote_confirm));
builder.setCancelable(true);

builder.setPositiveButton(
getResources().getString(R.string.quote_confirm_yes),
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
showProgress(true);
mDataHelper.createQuote(mSelectedQuote);
dialog.cancel();
}
});

builder.setNegativeButton(
getResources().getString(R.string.quote_confirm_no),
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.cancel();
}
});

AlertDialog confirmationAlert = builder.create();
confirmationAlert.show();
}

@Override
public void onIgnore(int requestID) {
showProgress(true);
mDataHelper.ignoreQuote(requestID);
}

private class Views {
RecyclerView mQuotesView;
View mProgressView;
TextView mNoDataView;

Views(View root) {
mQuotesView = (RecyclerView) root.findViewById(R.id.view_myquotes);
mProgressView = root.findViewById(R.id.progress_container_quotes);
mNoDataView = (TextView) root.findViewById(R.id.view_quotes_nodata);
}
}

}

[Screenshot "Are you sure you want to Quote AMOUNT  " ]

private void showConfirmationAlert() {
AlertDialog.Builder builder = new AlertDialog.Builder(getContext());
builder.setMessage(getResources().getString(R.string.quote_confirm));
builder.setCancelable(true);

builder.setPositiveButton(
getResources().getString(R.string.quote_confirm_yes),
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
showProgress(true);
mDataHelper.createQuote(mSelectedQuote);
dialog.cancel();
}
});

builder.setNegativeButton(
getResources().getString(R.string.quote_confirm_no),
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.cancel();
}
});

AlertDialog confirmationAlert = builder.create();
confirmationAlert.show();
}

最佳答案

  • 您将在 onQuote() 个月内获得 mSelectedQuote
  • 现在您可以在 mSelectedQuote 上获取金额
  • 将其传递给 showConfirmationAlert(amount);
  • 将其设置为 AlertDialog,如下所示 -

    private void showConfirmationAlert(int amount) {
    AlertDialog.Builder builder = new AlertDialog.Builder(getContext());
    builder.setMessage(getResources().getString(R.string.quote_confirm) + amount);

关于java - 在警报对话框中,我想显示所选值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35147472/

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