Skip to main content
Reversão para edição 2
Fonte Link
Math
  • 31,3mil
  • 15
  • 95
  • 132
public class Cliente {

private int mId;
private String mNome;

public Cliente(int id, String nome) {
    mId = id;
    mNome = nome;
}

public int getId() {
    return mId;
}

public String getNome() {
    return mNome;
}
 
public String toString() {
    return mNome;
}
public class RegistrarActivity extends AppCompatActivity {

private ImageView botaoVoltar;
private Button botaoRegistrar;
private EditText textoCPF, textoEmail;
private Spinner spinnerCliente;
private Cliente cliente;
private intString idcliente;
private ArrayList<Cliente> clientes = new ArrayList<>();
private RequestQueue requestQueue, requestQueue2;
private static final String URL = "http://www.caixinhadosmotoristas.com.br/spinner-cliente.php";
private static final String URLReg = "http://www.caixinhadosmotoristas.com.br/validacao.php?acao=register";
private StringRequest request, request2;
private ArrayAdapter arrayAdapter;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_registrar);

    botaoVoltar = (ImageView) findViewById(R.id.botaoVoltarId);
    botaoRegistrar = (Button) findViewById(R.id.botaoRegistrarId);
    textoCPF = (EditText) findViewById(R.id.textoCpfId);
    textoEmail = (EditText) findViewById(R.id.textoEmailId);
    spinnerCliente = (Spinner) findViewById(R.id.spinnerClienteId);

    requestQueue = Volley.newRequestQueue(this);
    requestQueue2 = Volley.newRequestQueue(this);

    RetornaJSONClientes();

    ArrayAdapter arrayAdapter = new ArrayAdapter (this, android.R.layout.simple_spinner_dropdown_item, clientes);
    arrayAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    spinnerCliente.setAdapter(arrayAdapter);

    spinnerCliente.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            cliente = (Cliente) parent.getItemAtPosition(position);
            idcliente = cliente.getId();
            Toast.makeText(RegistrarActivity.this, "" + idcliente, Toast.LENGTH_SHORT).show();"1";
        }

        @Override
        public void onNothingSelected(AdapterView<?> parent) {
            cliente = null;
        }
    });

    SimpleMaskFormatter mascaraCPF = new SimpleMaskFormatter("NNN.NNN.NNN-NN");
    MaskTextWatcher maskCPF = new MaskTextWatcher(textoCPF, mascaraCPF);
    textoCPF.addTextChangedListener(maskCPF);

    botaoRegistrar.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            request2 = new StringRequest(Request.Method.POST, URLReg, new Response.Listener<String>() {
                @Override
                public void onResponse(String response) {
                    try {
                        JSONObject jsonObject = new JSONObject(response);
                        if (jsonObject.names().get(0).equals("200")){
                            Toast.makeText(getApplicationContext(), jsonObject.getString("mensagem"), Toast.LENGTH_LONG).show();
                        } else {
                            Toast.makeText(getApplicationContext(), jsonObject.getString("mensagem"), Toast.LENGTH_LONG).show();
                        }
                    } catch (JSONException e) {
                        e.printStackTrace();
                    }
                }
            }, new Response.ErrorListener() {
                @Override
                public void onErrorResponse(VolleyError error) {

                }
            }){
                @Override
                protected Map<String, String> getParams() throws AuthFailureError {
                    idcliente = "" + cliente.getId();
                    HashMap<String, String> hashMap = new HashMap<String, String>();
                    hashMap.put("idcliente", idcliente);
                    hashMap.put("nome", cliente.getNome());
                    hashMap.put("cpf2", textoCPF.getText().toString());
                    hashMap.put("email", textoEmail.getText().toString());
                    return hashMap;
                }
            };

            requestQueue2.add(request2);
        }
    });

    botaoVoltar.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent voltaLogin = new Intent(RegistrarActivity.this, LoginActivity.class);
            startActivity(voltaLogin);
        }
    });
}

private void RetornaJSONClientes(){
    request = new StringRequest(Request.Method.POST, URL, new Response.Listener<String>() {
        @Override
        public void onResponse(String response) {
            String jsonString;
            int jsonInt;

            try {
                JSONArray jsonArray = new JSONArray(response);

                ArrayAdapter arrayAdapter = (ArrayAdapter) spinnerCliente.getAdapter();
                arrayAdapter.setNotifyOnChange(false);

                for(int i = 0; i < jsonArray.length(); i++){
                    jsonString = jsonArray.getJSONObject(i).getString("nome");
                    jsonInt = jsonArray.getJSONObject(i).getInt("idcliente");

                    clientes.add(new Cliente(jsonInt, jsonString));
                }

                arrayAdapter.setNotifyOnChange(true);
                arrayAdapter.notifyDataSetChanged();
            } catch (JSONException e) {
                e.printStackTrace();
            }
        }
    }, new Response.ErrorListener() {
        @Override
        public void onErrorResponse(VolleyError error) {

        }
    });

    requestQueue.add(request);
}
public class Cliente {

private int mId;
private String mNome;

public Cliente(int id, String nome) {
    mId = id;
    mNome = nome;
}

public int getId() {
    return mId;
}

public String getNome() {
    return mNome;
}
 
public String toString() {
    return mNome;
}
public class RegistrarActivity extends AppCompatActivity {

private ImageView botaoVoltar;
private Button botaoRegistrar;
private EditText textoCPF, textoEmail;
private Spinner spinnerCliente;
private Cliente cliente;
private int idcliente;
private ArrayList<Cliente> clientes = new ArrayList<>();
private RequestQueue requestQueue, requestQueue2;
private static final String URL = "http://www.caixinhadosmotoristas.com.br/spinner-cliente.php";
private static final String URLReg = "http://www.caixinhadosmotoristas.com.br/validacao.php?acao=register";
private StringRequest request, request2;
private ArrayAdapter arrayAdapter;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_registrar);

    botaoVoltar = (ImageView) findViewById(R.id.botaoVoltarId);
    botaoRegistrar = (Button) findViewById(R.id.botaoRegistrarId);
    textoCPF = (EditText) findViewById(R.id.textoCpfId);
    textoEmail = (EditText) findViewById(R.id.textoEmailId);
    spinnerCliente = (Spinner) findViewById(R.id.spinnerClienteId);

    requestQueue = Volley.newRequestQueue(this);
    requestQueue2 = Volley.newRequestQueue(this);

    RetornaJSONClientes();

    ArrayAdapter arrayAdapter = new ArrayAdapter (this, android.R.layout.simple_spinner_dropdown_item, clientes);
    arrayAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    spinnerCliente.setAdapter(arrayAdapter);

    spinnerCliente.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            cliente = (Cliente) parent.getItemAtPosition(position);
            idcliente = cliente.getId();
            Toast.makeText(RegistrarActivity.this, "" + idcliente, Toast.LENGTH_SHORT).show();
        }

        @Override
        public void onNothingSelected(AdapterView<?> parent) {
            cliente = null;
        }
    });

    SimpleMaskFormatter mascaraCPF = new SimpleMaskFormatter("NNN.NNN.NNN-NN");
    MaskTextWatcher maskCPF = new MaskTextWatcher(textoCPF, mascaraCPF);
    textoCPF.addTextChangedListener(maskCPF);

    botaoRegistrar.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            request2 = new StringRequest(Request.Method.POST, URLReg, new Response.Listener<String>() {
                @Override
                public void onResponse(String response) {
                    try {
                        JSONObject jsonObject = new JSONObject(response);
                        if (jsonObject.names().get(0).equals("200")){
                            Toast.makeText(getApplicationContext(), jsonObject.getString("mensagem"), Toast.LENGTH_LONG).show();
                        } else {
                            Toast.makeText(getApplicationContext(), jsonObject.getString("mensagem"), Toast.LENGTH_LONG).show();
                        }
                    } catch (JSONException e) {
                        e.printStackTrace();
                    }
                }
            }, new Response.ErrorListener() {
                @Override
                public void onErrorResponse(VolleyError error) {

                }
            }){
                @Override
                protected Map<String, String> getParams() throws AuthFailureError {
                    HashMap<String, String> hashMap = new HashMap<String, String>();
                    hashMap.put("nome", cliente.getNome());
                    hashMap.put("cpf2", textoCPF.getText().toString());
                    hashMap.put("email", textoEmail.getText().toString());
                    return hashMap;
                }
            };

            requestQueue2.add(request2);
        }
    });

    botaoVoltar.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent voltaLogin = new Intent(RegistrarActivity.this, LoginActivity.class);
            startActivity(voltaLogin);
        }
    });
}

private void RetornaJSONClientes(){
    request = new StringRequest(Request.Method.POST, URL, new Response.Listener<String>() {
        @Override
        public void onResponse(String response) {
            String jsonString;
            int jsonInt;

            try {
                JSONArray jsonArray = new JSONArray(response);

                ArrayAdapter arrayAdapter = (ArrayAdapter) spinnerCliente.getAdapter();
                arrayAdapter.setNotifyOnChange(false);

                for(int i = 0; i < jsonArray.length(); i++){
                    jsonString = jsonArray.getJSONObject(i).getString("nome");
                    jsonInt = jsonArray.getJSONObject(i).getInt("idcliente");

                    clientes.add(new Cliente(jsonInt, jsonString));
                }

                arrayAdapter.setNotifyOnChange(true);
                arrayAdapter.notifyDataSetChanged();
            } catch (JSONException e) {
                e.printStackTrace();
            }
        }
    }, new Response.ErrorListener() {
        @Override
        public void onErrorResponse(VolleyError error) {

        }
    });

    requestQueue.add(request);
}
public class Cliente {

private int mId;
private String mNome;

public Cliente(int id, String nome) {
    mId = id;
    mNome = nome;
}

public int getId() {
    return mId;
}

public String getNome() {
    return mNome;
}
public class RegistrarActivity extends AppCompatActivity {

private ImageView botaoVoltar;
private Button botaoRegistrar;
private EditText textoCPF, textoEmail;
private Spinner spinnerCliente;
private Cliente cliente;
private String idcliente;
private ArrayList<Cliente> clientes = new ArrayList<>();
private RequestQueue requestQueue, requestQueue2;
private static final String URL = "http://www.caixinhadosmotoristas.com.br/spinner-cliente.php";
private static final String URLReg = "http://www.caixinhadosmotoristas.com.br/validacao.php?acao=register";
private StringRequest request, request2;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_registrar);

    botaoVoltar = (ImageView) findViewById(R.id.botaoVoltarId);
    botaoRegistrar = (Button) findViewById(R.id.botaoRegistrarId);
    textoCPF = (EditText) findViewById(R.id.textoCpfId);
    textoEmail = (EditText) findViewById(R.id.textoEmailId);
    spinnerCliente = (Spinner) findViewById(R.id.spinnerClienteId);

    requestQueue = Volley.newRequestQueue(this);
    requestQueue2 = Volley.newRequestQueue(this);

    RetornaJSONClientes();

    ArrayAdapter arrayAdapter = new ArrayAdapter (this, android.R.layout.simple_spinner_dropdown_item, clientes);
    arrayAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    spinnerCliente.setAdapter(arrayAdapter);

    spinnerCliente.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            cliente = (Cliente) parent.getItemAtPosition(position);
            idcliente = "1";
        }

        @Override
        public void onNothingSelected(AdapterView<?> parent) {
            cliente = null;
        }
    });

    SimpleMaskFormatter mascaraCPF = new SimpleMaskFormatter("NNN.NNN.NNN-NN");
    MaskTextWatcher maskCPF = new MaskTextWatcher(textoCPF, mascaraCPF);
    textoCPF.addTextChangedListener(maskCPF);

    botaoRegistrar.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            request2 = new StringRequest(Request.Method.POST, URLReg, new Response.Listener<String>() {
                @Override
                public void onResponse(String response) {
                    try {
                        JSONObject jsonObject = new JSONObject(response);
                        if (jsonObject.names().get(0).equals("200")){
                            Toast.makeText(getApplicationContext(), jsonObject.getString("mensagem"), Toast.LENGTH_LONG).show();
                        } else {
                            Toast.makeText(getApplicationContext(), jsonObject.getString("mensagem"), Toast.LENGTH_LONG).show();
                        }
                    } catch (JSONException e) {
                        e.printStackTrace();
                    }
                }
            }, new Response.ErrorListener() {
                @Override
                public void onErrorResponse(VolleyError error) {

                }
            }){
                @Override
                protected Map<String, String> getParams() throws AuthFailureError {
                    idcliente = "" + cliente.getId();
                    HashMap<String, String> hashMap = new HashMap<String, String>();
                    hashMap.put("idcliente", idcliente);
                    hashMap.put("nome", cliente.getNome());
                    hashMap.put("cpf2", textoCPF.getText().toString());
                    hashMap.put("email", textoEmail.getText().toString());
                    return hashMap;
                }
            };

            requestQueue2.add(request2);
        }
    });

    botaoVoltar.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent voltaLogin = new Intent(RegistrarActivity.this, LoginActivity.class);
            startActivity(voltaLogin);
        }
    });
}

private void RetornaJSONClientes(){
    request = new StringRequest(Request.Method.POST, URL, new Response.Listener<String>() {
        @Override
        public void onResponse(String response) {
            String jsonString;
            int jsonInt;

            try {
                JSONArray jsonArray = new JSONArray(response);

                for(int i = 0; i < jsonArray.length(); i++){
                    jsonString = jsonArray.getJSONObject(i).getString("nome");
                    jsonInt = jsonArray.getJSONObject(i).getInt("idcliente");

                    clientes.add(new Cliente(jsonInt, jsonString));
                }
            } catch (JSONException e) {
                e.printStackTrace();
            }
        }
    }, new Response.ErrorListener() {
        @Override
        public void onErrorResponse(VolleyError error) {

        }
    });

    requestQueue.add(request);
}
adicionou 269 caracteres ao conteúdo
Fonte Link
public class Cliente {

private int mId;
private String mNome;

public Cliente(int id, String nome) {
    mId = id;
    mNome = nome;
}

public int getId() {
    return mId;
}

public String getNome() {
    return mNome;
} 

public String toString() {
    return mNome;
}
public class RegistrarActivity extends AppCompatActivity {

private ImageView botaoVoltar;
private Button botaoRegistrar;
private EditText textoCPF, textoEmail;
private Spinner spinnerCliente;
private Cliente cliente;
private Stringint idcliente;
private ArrayList<Cliente> clientes = new ArrayList<>();
private RequestQueue requestQueue, requestQueue2;
private static final String URL = "http://www.caixinhadosmotoristas.com.br/spinner-cliente.php";
private static final String URLReg = "http://www.caixinhadosmotoristas.com.br/validacao.php?acao=register";
private StringRequest request, request2;
private ArrayAdapter arrayAdapter;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_registrar);

    botaoVoltar = (ImageView) findViewById(R.id.botaoVoltarId);
    botaoRegistrar = (Button) findViewById(R.id.botaoRegistrarId);
    textoCPF = (EditText) findViewById(R.id.textoCpfId);
    textoEmail = (EditText) findViewById(R.id.textoEmailId);
    spinnerCliente = (Spinner) findViewById(R.id.spinnerClienteId);

    requestQueue = Volley.newRequestQueue(this);
    requestQueue2 = Volley.newRequestQueue(this);

    RetornaJSONClientes();

    ArrayAdapter arrayAdapter = new ArrayAdapter (this, android.R.layout.simple_spinner_dropdown_item, clientes);
    arrayAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    spinnerCliente.setAdapter(arrayAdapter);

    spinnerCliente.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            cliente = (Cliente) parent.getItemAtPosition(position);
            idcliente = "1";cliente.getId();
            Toast.makeText(RegistrarActivity.this, "" + idcliente, Toast.LENGTH_SHORT).show();
        }

        @Override
        public void onNothingSelected(AdapterView<?> parent) {
            cliente = null;
        }
    });

    SimpleMaskFormatter mascaraCPF = new SimpleMaskFormatter("NNN.NNN.NNN-NN");
    MaskTextWatcher maskCPF = new MaskTextWatcher(textoCPF, mascaraCPF);
    textoCPF.addTextChangedListener(maskCPF);

    botaoRegistrar.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            request2 = new StringRequest(Request.Method.POST, URLReg, new Response.Listener<String>() {
                @Override
                public void onResponse(String response) {
                    try {
                        JSONObject jsonObject = new JSONObject(response);
                        if (jsonObject.names().get(0).equals("200")){
                            Toast.makeText(getApplicationContext(), jsonObject.getString("mensagem"), Toast.LENGTH_LONG).show();
                        } else {
                            Toast.makeText(getApplicationContext(), jsonObject.getString("mensagem"), Toast.LENGTH_LONG).show();
                        }
                    } catch (JSONException e) {
                        e.printStackTrace();
                    }
                }
            }, new Response.ErrorListener() {
                @Override
                public void onErrorResponse(VolleyError error) {

                }
            }){
                @Override
                protected Map<String, String> getParams() throws AuthFailureError {
                    idcliente = "" + cliente.getId();
                    HashMap<String, String> hashMap = new HashMap<String, String>();
                    hashMap.put("idcliente", idcliente);
                    hashMap.put("nome", cliente.getNome());
                    hashMap.put("cpf2", textoCPF.getText().toString());
                    hashMap.put("email", textoEmail.getText().toString());
                    return hashMap;
                }
            };

            requestQueue2.add(request2);
        }
    });

    botaoVoltar.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent voltaLogin = new Intent(RegistrarActivity.this, LoginActivity.class);
            startActivity(voltaLogin);
        }
    });
}

private void RetornaJSONClientes(){
    request = new StringRequest(Request.Method.POST, URL, new Response.Listener<String>() {
        @Override
        public void onResponse(String response) {
            String jsonString;
            int jsonInt;

            try {
                JSONArray jsonArray = new JSONArray(response);

                ArrayAdapter arrayAdapter = (ArrayAdapter) spinnerCliente.getAdapter();
                arrayAdapter.setNotifyOnChange(false);

                for(int i = 0; i < jsonArray.length(); i++){
                    jsonString = jsonArray.getJSONObject(i).getString("nome");
                    jsonInt = jsonArray.getJSONObject(i).getInt("idcliente");

                    clientes.add(new Cliente(jsonInt, jsonString));
                }

                arrayAdapter.setNotifyOnChange(true);
                arrayAdapter.notifyDataSetChanged();
            } catch (JSONException e) {
                e.printStackTrace();
            }
        }
    }, new Response.ErrorListener() {
        @Override
        public void onErrorResponse(VolleyError error) {

        }
    });

    requestQueue.add(request);
}

inserir a descrição da imagem aqui

public class Cliente {

private int mId;
private String mNome;

public Cliente(int id, String nome) {
    mId = id;
    mNome = nome;
}

public int getId() {
    return mId;
}

public String getNome() {
    return mNome;
}
public class RegistrarActivity extends AppCompatActivity {

private ImageView botaoVoltar;
private Button botaoRegistrar;
private EditText textoCPF, textoEmail;
private Spinner spinnerCliente;
private Cliente cliente;
private String idcliente;
private ArrayList<Cliente> clientes = new ArrayList<>();
private RequestQueue requestQueue, requestQueue2;
private static final String URL = "http://www.caixinhadosmotoristas.com.br/spinner-cliente.php";
private static final String URLReg = "http://www.caixinhadosmotoristas.com.br/validacao.php?acao=register";
private StringRequest request, request2;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_registrar);

    botaoVoltar = (ImageView) findViewById(R.id.botaoVoltarId);
    botaoRegistrar = (Button) findViewById(R.id.botaoRegistrarId);
    textoCPF = (EditText) findViewById(R.id.textoCpfId);
    textoEmail = (EditText) findViewById(R.id.textoEmailId);
    spinnerCliente = (Spinner) findViewById(R.id.spinnerClienteId);

    requestQueue = Volley.newRequestQueue(this);
    requestQueue2 = Volley.newRequestQueue(this);

    RetornaJSONClientes();

    ArrayAdapter arrayAdapter = new ArrayAdapter (this, android.R.layout.simple_spinner_dropdown_item, clientes);
    arrayAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    spinnerCliente.setAdapter(arrayAdapter);

    spinnerCliente.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            cliente = (Cliente) parent.getItemAtPosition(position);
            idcliente = "1";
        }

        @Override
        public void onNothingSelected(AdapterView<?> parent) {
            cliente = null;
        }
    });

    SimpleMaskFormatter mascaraCPF = new SimpleMaskFormatter("NNN.NNN.NNN-NN");
    MaskTextWatcher maskCPF = new MaskTextWatcher(textoCPF, mascaraCPF);
    textoCPF.addTextChangedListener(maskCPF);

    botaoRegistrar.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            request2 = new StringRequest(Request.Method.POST, URLReg, new Response.Listener<String>() {
                @Override
                public void onResponse(String response) {
                    try {
                        JSONObject jsonObject = new JSONObject(response);
                        if (jsonObject.names().get(0).equals("200")){
                            Toast.makeText(getApplicationContext(), jsonObject.getString("mensagem"), Toast.LENGTH_LONG).show();
                        } else {
                            Toast.makeText(getApplicationContext(), jsonObject.getString("mensagem"), Toast.LENGTH_LONG).show();
                        }
                    } catch (JSONException e) {
                        e.printStackTrace();
                    }
                }
            }, new Response.ErrorListener() {
                @Override
                public void onErrorResponse(VolleyError error) {

                }
            }){
                @Override
                protected Map<String, String> getParams() throws AuthFailureError {
                    idcliente = "" + cliente.getId();
                    HashMap<String, String> hashMap = new HashMap<String, String>();
                    hashMap.put("idcliente", idcliente);
                    hashMap.put("nome", cliente.getNome());
                    hashMap.put("cpf2", textoCPF.getText().toString());
                    hashMap.put("email", textoEmail.getText().toString());
                    return hashMap;
                }
            };

            requestQueue2.add(request2);
        }
    });

    botaoVoltar.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent voltaLogin = new Intent(RegistrarActivity.this, LoginActivity.class);
            startActivity(voltaLogin);
        }
    });
}

private void RetornaJSONClientes(){
    request = new StringRequest(Request.Method.POST, URL, new Response.Listener<String>() {
        @Override
        public void onResponse(String response) {
            String jsonString;
            int jsonInt;

            try {
                JSONArray jsonArray = new JSONArray(response);

                for(int i = 0; i < jsonArray.length(); i++){
                    jsonString = jsonArray.getJSONObject(i).getString("nome");
                    jsonInt = jsonArray.getJSONObject(i).getInt("idcliente");

                    clientes.add(new Cliente(jsonInt, jsonString));
                }
            } catch (JSONException e) {
                e.printStackTrace();
            }
        }
    }, new Response.ErrorListener() {
        @Override
        public void onErrorResponse(VolleyError error) {

        }
    });

    requestQueue.add(request);
}

inserir a descrição da imagem aqui

public class Cliente {

private int mId;
private String mNome;

public Cliente(int id, String nome) {
    mId = id;
    mNome = nome;
}

public int getId() {
    return mId;
}

public String getNome() {
    return mNome;
} 

public String toString() {
    return mNome;
}
public class RegistrarActivity extends AppCompatActivity {

private ImageView botaoVoltar;
private Button botaoRegistrar;
private EditText textoCPF, textoEmail;
private Spinner spinnerCliente;
private Cliente cliente;
private int idcliente;
private ArrayList<Cliente> clientes = new ArrayList<>();
private RequestQueue requestQueue, requestQueue2;
private static final String URL = "http://www.caixinhadosmotoristas.com.br/spinner-cliente.php";
private static final String URLReg = "http://www.caixinhadosmotoristas.com.br/validacao.php?acao=register";
private StringRequest request, request2;
private ArrayAdapter arrayAdapter;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_registrar);

    botaoVoltar = (ImageView) findViewById(R.id.botaoVoltarId);
    botaoRegistrar = (Button) findViewById(R.id.botaoRegistrarId);
    textoCPF = (EditText) findViewById(R.id.textoCpfId);
    textoEmail = (EditText) findViewById(R.id.textoEmailId);
    spinnerCliente = (Spinner) findViewById(R.id.spinnerClienteId);

    requestQueue = Volley.newRequestQueue(this);
    requestQueue2 = Volley.newRequestQueue(this);

    RetornaJSONClientes();

    ArrayAdapter arrayAdapter = new ArrayAdapter (this, android.R.layout.simple_spinner_dropdown_item, clientes);
    arrayAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    spinnerCliente.setAdapter(arrayAdapter);

    spinnerCliente.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            cliente = (Cliente) parent.getItemAtPosition(position);
            idcliente = cliente.getId();
            Toast.makeText(RegistrarActivity.this, "" + idcliente, Toast.LENGTH_SHORT).show();
        }

        @Override
        public void onNothingSelected(AdapterView<?> parent) {
            cliente = null;
        }
    });

    SimpleMaskFormatter mascaraCPF = new SimpleMaskFormatter("NNN.NNN.NNN-NN");
    MaskTextWatcher maskCPF = new MaskTextWatcher(textoCPF, mascaraCPF);
    textoCPF.addTextChangedListener(maskCPF);

    botaoRegistrar.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            request2 = new StringRequest(Request.Method.POST, URLReg, new Response.Listener<String>() {
                @Override
                public void onResponse(String response) {
                    try {
                        JSONObject jsonObject = new JSONObject(response);
                        if (jsonObject.names().get(0).equals("200")){
                            Toast.makeText(getApplicationContext(), jsonObject.getString("mensagem"), Toast.LENGTH_LONG).show();
                        } else {
                            Toast.makeText(getApplicationContext(), jsonObject.getString("mensagem"), Toast.LENGTH_LONG).show();
                        }
                    } catch (JSONException e) {
                        e.printStackTrace();
                    }
                }
            }, new Response.ErrorListener() {
                @Override
                public void onErrorResponse(VolleyError error) {

                }
            }){
                @Override
                protected Map<String, String> getParams() throws AuthFailureError {
                    HashMap<String, String> hashMap = new HashMap<String, String>();
                    hashMap.put("nome", cliente.getNome());
                    hashMap.put("cpf2", textoCPF.getText().toString());
                    hashMap.put("email", textoEmail.getText().toString());
                    return hashMap;
                }
            };

            requestQueue2.add(request2);
        }
    });

    botaoVoltar.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent voltaLogin = new Intent(RegistrarActivity.this, LoginActivity.class);
            startActivity(voltaLogin);
        }
    });
}

private void RetornaJSONClientes(){
    request = new StringRequest(Request.Method.POST, URL, new Response.Listener<String>() {
        @Override
        public void onResponse(String response) {
            String jsonString;
            int jsonInt;

            try {
                JSONArray jsonArray = new JSONArray(response);

                ArrayAdapter arrayAdapter = (ArrayAdapter) spinnerCliente.getAdapter();
                arrayAdapter.setNotifyOnChange(false);

                for(int i = 0; i < jsonArray.length(); i++){
                    jsonString = jsonArray.getJSONObject(i).getString("nome");
                    jsonInt = jsonArray.getJSONObject(i).getInt("idcliente");

                    clientes.add(new Cliente(jsonInt, jsonString));
                }

                arrayAdapter.setNotifyOnChange(true);
                arrayAdapter.notifyDataSetChanged();
            } catch (JSONException e) {
                e.printStackTrace();
            }
        }
    }, new Response.ErrorListener() {
        @Override
        public void onErrorResponse(VolleyError error) {

        }
    });

    requestQueue.add(request);
}
adicionou 97 caracteres ao conteúdo
Fonte Link

inserir a descrição da imagem aqui

inserir a descrição da imagem aqui

adicionou 4794 caracteres ao conteúdo
Fonte Link
Carregando
Fonte Link
Carregando