mardi 4 juillet 2017

how to get value listview checkbox on another activity with sqlite

I have an app with a checkbox that retrieves data from sqlite and if checkbox is checked, I want to get a value in Textview on another activity. So far i have tried with a toast

//First Activity

FloatingActionButton fab = (FloatingActionButton) v.findViewById(R.id.fab);
        fab.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                sb = new StringBuffer();

                for (Gejala gejala : adapter.checkedGejalas) {
                    sb.append(gejala.getNama_gejala());
                    sb.append("\n");
                }

                if (adapter.checkedGejalas.size()>0) {
                    Intent i = new Intent(getActivity(), DiagnosapenyakituserActivity.class);
                    i.putExtra("nama_gejala", sb.toString());
                    startActivity(i);
                } else {
                    Toast.makeText(getActivity(), "Minimal pilih 2 Gejala", Toast.LENGTH_SHORT).show();
                }
            }
        });

//Second Activity

    @Override
    protected void onCreate(Bundle savedInstaceState) {
        super.onCreate(savedInstaceState);
        setContentView(R.layout.activity_diagnosapenyakituser);

        databaseHelper = new DatabaseHelper(this);
        tvGejalaTerpilihUser = (TextView)findViewById(R.id.tvGejalaTerpilihUser);

        SQLiteDatabase db = databaseHelper.getReadableDatabase();
        cursor = db.rawQuery("SELECT * FROM Gejala WHERE nama_gejala = '" +
                getIntent().getStringExtra("nama_gejala") + "'", null);
        cursor.moveToFirst();
        if (cursor.getCount()>0) {
            cursor.moveToPosition(0);
            tvGejalaTerpilihUser.setText(cursor.getString(0).toString());
        }
            getIntent().getExtras();
    }




Aucun commentaire:

Enregistrer un commentaire