mercredi 29 juin 2016

Can not call class android

I have code using onClickListener, I'm trying to call class NetCheck but error like this http://prntscr.com/blgi94. When I try put the class NetCheck in outside onClickListener get error in this line http://prntscr.com/blginf. I don't know how to fix it. Anyone can help me?

My code

premi.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View arg0) {
            // get prompts.xml view
            LayoutInflater li = LayoutInflater.from(context);
            View promptsView = li.inflate(R.layout.update, null);
            AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(
                    context);
            // set prompts.xml to alertdialog builder
            alertDialogBuilder.setView(promptsView);
            final EditText userInput = (EditText) promptsView
                    .findViewById(R.id.editTextDialogUserInput);
            userInput.setText(cash.getText());
            // set dialog message
            alertDialogBuilder
                    .setCancelable(false)
                    .setPositiveButton("OK",
                            new DialogInterface.OnClickListener() {
                                public void onClick(DialogInterface dialog,int id) {
                                    // get user input and set it to result
                                    // edit text
                                    //result.setText(userInput.getText());
                                    class NetCheck extends AsyncTask<String, String, String> {

                                        /**
                                         * Before starting background thread Show Progress Dialog
                                         * */
                                        @Override
                                        protected void onPreExecute() {
                                            super.onPreExecute();
                                            pDialog = new ProgressDialog(IGNActivity.this);
                                            pDialog.setMessage("Creating ID Game Master..");
                                            pDialog.setIndeterminate(false);
                                            pDialog.setCancelable(true);
                                            pDialog.show();
                                        }

                                        /**
                                         * Creating product
                                         * */
                                        protected String doInBackground(String... args) {
                                            String ign = editTextId.getText().toString().trim();
                                            String cash = userInput.getText().toString();

                                            // Building Parameters
                                            List<NameValuePair> params = new ArrayList<NameValuePair>();
                                            params.add(new BasicNameValuePair("ign", ign));
                                            params.add(new BasicNameValuePair("cash", cash));

                                            // getting JSON Object
                                            // Note that create product url accepts POST method
                                            JSONObject json = jsonParser.makeHttpRequest(url_input_item,
                                                    "POST", params);

                                            // check log cat fro response
                                            Log.d("Create Response", json.toString());

                                            // check for success tag
                                            try {
                                                int success = json.getInt(TAG_SUCCESS);

                                                if (success == 1) {
                                                    // successfully created product
                                                    //Toast.makeText(CreateIDGM.this, "Success Create ID Game Master ", Toast.LENGTH_SHORT).show();


                                                    // closing this screen
                                                    finish();
                                                } else {
                                                    // failed to create product
                                                }
                                            } catch (JSONException e) {
                                                e.printStackTrace();
                                            }
                                            return null;
                                        }
                                        protected void onPostExecute(String file_url) {
                                            // dismiss the dialog once done
                                            pDialog.dismiss();
                                            Intent i = new Intent(getApplicationContext(), IGNActivity.class);
                                            startActivity(i);
                                            Toast.makeText(IGNActivity.this, "Success Input Item ", Toast.LENGTH_SHORT).show();
                                        }
                                    }
                                }
                            })
                    .setNegativeButton("Cancel",
                            new DialogInterface.OnClickListener() {
                                public void onClick(DialogInterface dialog,int id) {
                                    dialog.cancel();
                                }
                            });


            // create alert dialog
            AlertDialog alertDialog = alertDialogBuilder.create();
            // show it
            alertDialog.show();
        }
    });

Aucun commentaire:

Enregistrer un commentaire