Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Crash Problem! #6

Open
JamesLiAndroid opened this issue Apr 6, 2017 · 0 comments
Open

Crash Problem! #6

JamesLiAndroid opened this issue Apr 6, 2017 · 0 comments

Comments

@JamesLiAndroid
Copy link

You need to use a Theme.AppCompat theme (or descendant) with this activity

When I use the component in my project, I have got this Error message!

So I have found the code and located the error at the following code:

else if (v == mTextViewQuantity) {
if (!quantityDialog) return;

        if (mTextViewClickListener != null) {
            mTextViewClickListener.onClick(v);
            return;
        }
        // Crash at this line!
        AlertDialog.Builder builder = new AlertDialog.Builder(getContext());
        builder.setTitle(labelDialogTitle);

        final View inflate = LayoutInflater.from(getContext()).inflate(R.layout.qv_dialog_changequantity, null, false);
        final EditText et = (EditText) inflate.findViewById(R.id.qv_et_change_qty);
        et.setText(String.valueOf(quantity));

        builder.setView(inflate);
        builder.setPositiveButton(labelPositiveButton, null);
        final AlertDialog dialog = builder.show();
        dialog.getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                String newQuantity = et.getText().toString();
                if (isValidNumber(newQuantity)) {
                    int intNewQuantity = Integer.parseInt(newQuantity);
                    Log.d(VIEW_LOG_TAG, "newQuantity " + intNewQuantity + " max " + maxQuantity);
                    if (intNewQuantity > maxQuantity) {
                        Toast.makeText(getContext(), "Maximum quantity allowed is " + maxQuantity, Toast.LENGTH_LONG).show();
                    } else if (intNewQuantity < minQuantity) {
                        Toast.makeText(getContext(), "Minimum quantity allowed is " + minQuantity, Toast.LENGTH_LONG).show();
                    } else {
                        setQuantity(intNewQuantity);
                        hideKeyboard(et);
                        dialog.dismiss();
                    }

                } else {
                    Toast.makeText(getContext(), "Enter valid number", Toast.LENGTH_LONG).show();
                }
            }
        });
    } 

getContext() should be replaced by getActivity(). Currently I have to note the code to solve this problem!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant