我可以使用我的数据库填充我的微调器,但我无法显示所选项

时间:2016-12-09 06:37:08

标签: android android-studio spinner asynchttpclient

我正在android studio中开展一个小项目,我遇到了问题,我使用ArrayAdapter从JSON代码中捕获信息,现在我可以显示数据,但是当我选择一个项目时它没有显示在微调器的显示中,我希望你能帮助我,这是我的代码:

public class Asistencia extends AppCompatActivity implements AdapterView.OnItemSelectedListener{

    ProgressDialog progressDialog;
    private String END_POINT_URL = "http://192.168.0.6:1434/Bitacora/Usuarios.php";
    private Spinner p1;
    private List<String> listu =new ArrayList<String>();
    private String[] listu1 = new String [100];

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

        progressDialog = new ProgressDialog(this);
        progressDialog.setMessage("Por favor espere...");
        progressDialog.setCancelable(false);

        p1 = (Spinner) findViewById(R.id.spinnerUsuario);
        ArrayAdapter<String>dataAdapter = new ArrayAdapter<String>(this,
                android.R.layout.simple_list_item_1, listu);

        dataAdapter.setDropDownViewResource(android.R.layout.simple_list_item_1);
        p1.setAdapter(dataAdapter);


        p1.setOnItemSelectedListener(this);
        dataAdapter.notifyDataSetChanged();

        callRegisterSpinnerU();
    }
    @Override public void onItemSelected(AdapterView parent, View view, int position, long id) {

    }

    @Override
    public void onNothingSelected(AdapterView<?> parent) {

    }

    private void callRegisterSpinnerU()
    {
        progressDialog.show();

        final AsyncHttpClient client = new AsyncHttpClient();

        client.post(END_POINT_URL, new AsyncHttpResponseHandler(){

            @Override
            public void onSuccess(int statusCode, String content) {
                progressDialog.hide();


                try {

                    JSONObject obj = new JSONObject(content);
                    final JSONArray jsonArray = obj.getJSONArray("users");
                    int length = jsonArray.length();
                    for (int i = 0; i < length; i++)
                    {
                        JSONObject user = jsonArray.getJSONObject(i);
                        listu.add(user.getString("Usuario"));

                    }
                }catch(JSONException e){
                    Toast.makeText(getApplicationContext(), "Error al enviar su solicitud, Verifique el Json" + e.toString(), Toast.LENGTH_LONG).show();
                }
            }
            @Override
            public void onFailure(int statusCode, Throwable error, String content) {
                progressDialog.hide();

                if(statusCode == 404){
                    Toast.makeText(getApplicationContext(), "No se envio la solicitud", Toast.LENGTH_LONG).show();
                }
                else if(statusCode == 500){
                    Toast.makeText(getApplicationContext(), "Algo ocurrio al final", Toast.LENGTH_LONG).show();
                }
                else{
                    Toast.makeText(getApplicationContext(), "Error: El dispositivo tal vez no este conectado a la red o el server se encuentra sin funcionar", Toast.LENGTH_LONG).show();
                }
            }
        });
    }
}

当我尝试从微调器中选择一个项目时,我在logcat中收到此消息:

  

12-09 00:24:56.063 8171-8171 / com.example.crisis.bitacora   W / InputEventReceiver:尝试完成输入事件但输入   事件接收者已被处理。

抱歉我的英语不好:(。

2 个答案:

答案 0 :(得分:0)

当listu更改时,您没有通知dataAdapter;

尝试调用dataAdapter.notifyDataSetChanged();从网络获得数据成功。

答案 1 :(得分:0)

只需添加:

20161209 12:24:58.497   WARN    Application has failed.     
20161209 12:24:58.499   WARN    No working Internet connection available    
20161209 12:24:58.501   WARN    this build has no associated authentication!