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

I can populate my spinner with my database but I can't show the selected item

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

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();
                }
            }
        });
    }
}

当我尝试 select 来自微调器的项目时,我在 logcat:

中收到此消息

12-09 00:24:56.063 8171-8171/com.example.crisis.bitacora W/InputEventReceiver: Attempted to finish an input event but the input event receiver has already been disposed.

对不起我的英语不好:(。

listu改变时你没有通知dataAdapter;

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

只需添加:

  public void onItemSelected(AdapterView parent, View view, int position, long id) {


    p1.setSelection(position);
    }