无法获取与数据库

时间:2018-03-13 13:43:18

标签: android-volley android-checkbox

我是android的新程序员,我从数据库得到响应,我在创建数据的同时创建复选框,但问题是当我想获取每个复选框的值时,我只能得到最后一个。我在网上checkecd我没有找到任何解决方案

这是我的代码,从json使用volley

获取数据库中的数据
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_filiere);
    L1=(LinearLayout) findViewById(R.id.filiere);

    if(!SharedPrefManager.getInstance(this).isLoggedIn()){
        finish();
        startActivity(new Intent(this,LoginActivity.class));
    }
    ProfileActivity prof=new ProfileActivity();
    if(prof.clicked==false){
        afficheData();
    }
    Toast.makeText(Filiere.this,"Clicked= "+prof.clicked+"",Toast.LENGTH_SHORT).show();

    btnfiliere=(Button)findViewById(R.id.Btnfiliere);
    btnfiliere.setOnClickListener(this);

}

void afficheData(){
    StringRequest jsonObjectRequest= new StringRequest(Request.Method.POST,Constants.URl_Diplome, new Response.Listener<String>() {

        @Override
        public void onResponse(String response) {
            try {
                JSONArray obj= new JSONArray(response);

                for(int i=0;i<obj.length();i++){
                    JSONObject Qu= obj.getJSONObject(i);
                    String id_dip=Qu.getString("Id_diplome");
                    String Nom=Qu.getString("Nom_diplome");
                    Toast.makeText(Filiere.this,"Success Affichage id="+id_dip+"Nom"+Nom,Toast.LENGTH_SHORT).show();
                    Log.i("MyActivity", "MyClass.getView() — get item number " +id_dip+" !!! "+Nom);
                    addCheck(id_dip,Nom);
                    num_check=num_check+1;
                }

                //startActivity(new Intent(getApplicationContext(),Responses.class));
            } catch (JSONException e) {
                e.printStackTrace();
            }

        }
    }, new Response.ErrorListener() {
        @Override
        public void onErrorResponse(VolleyError error) {

            Toast.makeText(
                    getApplicationContext(),
                    error.getMessage()+"=== FAMA MOCHKLAA YAA MAALEM   :",
                    Toast.LENGTH_LONG
            ).show();
        }
    }
    );
    //requestQueue.add(jsonObjectRequest);
    RequestHandler.getInstance(this).addToRequestQueue(jsonObjectRequest);
}

public CheckBox addCheck(String id_dip,String Nom){
    CheckBox checkBox = new CheckBox(this);
    checkBox.setId(Integer.parseInt(id_dip));
    checkBox.setText(Nom);
    checkBox.setTag(id_dip);
    Toast.makeText(Filiere.this,"Created",Toast.LENGTH_SHORT).show();
    checkBox.setOnClickListener(this);
    L1.addView(checkBox);
    if(checkBox.isChecked()){
        Toast.makeText(Filiere.this,"You cliked me "+checkBox.getId(),Toast.LENGTH_SHORT).show();
    }
    return checkBox;

}

@Override
public void onClick(View view) {
    if (view == btnfiliere){
        verifCheck();
    }
}
void verifCheck(){

}

}

0 个答案:

没有答案