user1528724
user1528724

Reputation: 11

how to invoke a service's android method since void onclick function?

hello I'm trying to invoke a service's android method since a public void onclick and i have one mistake, it tell that i need insert "AssignemetOperator Expression" to complete the expresion, but i don't see where it's the mistake. i put de code here the mistake is on the boolean ret=bindService(......... it´s inside of public void onClick idcamarero was created how a global variable thanks

View.OnClickListener buttonhandler=new View.OnClickListener() {

    public void onClick(View v) {
        EditText id_camarero = (EditText) findViewById(R.id.id_camarero);
        String numero = id_camarero.getText().toString();
        idcamarero=Integer.parseInt(numero);
        //Register the actions we want to receive via broadcast
        //MyService.LocalBinder.
     boolean ret= bindService(new Intent(MainActivity.this, MyService.class), androidServiceConnection, BIND_AUTO_CREATE);          
         IntentFilter filter = new IntentFilter(MyService.DATA_RECEIVED_INTENT);
         registerReceiver(androidListener, filter);
     if((numero.trim().equals(""))||(existe==false)){
         AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(context);

                // set title
                alertDialogBuilder.setTitle("Fallo de id");

                // set dialog message
                alertDialogBuilder
                    //.setMessage("Click salir para finalizarprograma")
                    .setCancelable(false)
                    .setPositiveButton("Salir",new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog,int id) {
                            // if this button is clicked, close
                            // current activity
                            MainActivity.this.finish();
                        }
                      })
                    .setNegativeButton("Reintentar",new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog,int id) {
                            // if this button is clicked, just close
                            // the dialog box and do nothing
                            dialog.cancel();
                        }
                    });

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

                    // show it
                    alertDialog.show();
                }

     else{
    // Intent intent= new Intent(GestorRestauranteActivity.this,MenuMesas.class);
    // intent.putExtra("id", numero);//enviamos el id de camarero a la actividad que invocamos
    // startActivity(intent);
     finish();
     }
    }

};

Upvotes: 0

Views: 159

Answers (1)

David Wasser
David Wasser

Reputation: 95646

The 5th line of your code:

idcamarero=Integer.parseInt(numero);

won't parse because you haven't declared the type of the variable idcamarero. Either you need to prefix the line with int or just remove it entirely (it doesn't look like you need this).

Upvotes: 0

Related Questions