automatically show value when choose multiple checkbox in android studio

42
April 19, 2019, at 01:50 AM

I'am newer. I get a problem at java.

How to doing and automatically value want i click multiple checkbox? this is my java code.

public class StepsTaken extends AppCompatActivity {

TextView mtextView;
Button bSaveST, mBtn;
FirebaseDatabase database;
DatabaseReference reff;

// private ArrayList arrayList = new ArrayList<>(); // private ArrayAdapter adapter;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_steps_taken);
    //adapter  = new ArrayAdapter<Integer>(this, android.R.layout.simple_list_item_1, arrayList);

    Button mBtn = (Button) findViewById(R.id.btnAdd);
    final TextView mtextView = (TextView) findViewById(R.id.textviewAdd);
    mBtn.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            AlertDialog.Builder builder = new AlertDialog.Builder(StepsTaken.this);
            String[] foods = new String[] {"Ayam goreng", "Ayam tandoori", "Burger", "Capati", "Ikan kembong ", "Karipap", "Nasi lemak ", "Nasi ayam ", "Nasi putih ", "Mee goreng ", "Mee Sup", "Telor goreng ","Popia goreng", "Pisang goreng", "Sandwich Sardin", "Tea", "Kopi", "Nescafe Ais", "Milo Ais", "Minuman Kotak"};
            int[] val1 = {0, 255, 220, 425, 300, 140, 180, 400, 300, 260, 660, 380, 110, 170, 180, 70, 0, 150, 150, 350, 300, 105};
            final boolean[] checkedFoods = new boolean[] {
                    false,
                    false,
                    false,
                    false,
                    false,
                    false,
                    false,
                    false,
                    false,
                    false,
                    false,
                    false,
                    false,
                    false,
                    false,
                    false,
                    false,
                    false,
                    false,
                    false,
            };
            final List<String> foodList = Arrays.asList(foods);
            builder.setMultiChoiceItems(foods, checkedFoods, new DialogInterface.OnMultiChoiceClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which, boolean isChecked) {
                    checkedFoods[which] = isChecked;
                    String currentItem = foodList.get(which);
                    Toast.makeText(getApplicationContext(),
                            currentItem + " " + isChecked, Toast.LENGTH_SHORT).show();
                }
            });
            builder.setCancelable(false);
            builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                // Do something when click positive button
                for (int i = 0; i<checkedFoods.length; i++){
                    boolean checked = checkedFoods[i];
                    if (checked) {
                        mtextView.setText(mtextView.getText() + foodList.get(i) + "\n");
                    }
                }
            }
            });
            builder.setNegativeButton("NO", new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    // Do something when click the negative button
                }
            });
            builder.setNeutralButton("CANCEL", new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    // Do something when click the neutral button
                }
            });
            AlertDialog dialog = builder.create();
            // Display the alert dialog on interface
            dialog.show();
        }
    });

so, how can i show the value when i click multiple checkbox? or maybe my code should add more source code?

READ ALSO
Install Protobuf on My Rooted Android Phone [on hold]

Install Protobuf on My Rooted Android Phone [on hold]

Folks, I have a rooted android phoneIt has protobuf 3

51
DJI SDK: Pause/Resume Waypoint mission when arriving on point?

DJI SDK: Pause/Resume Waypoint mission when arriving on point?

I haven't found any info on thisI'd like to build a waypoint mission like this:

19
3d model construction using depth cameras [on hold]

3d model construction using depth cameras [on hold]

Many modern Android phones are equipped with depth (camera) sensorsI am trying to construct a 3d model (using 3d modeling software such as meshlab) of a physical object that is being scanned by a depth (camera) sensor on my Android phone (e

13
Simplier explanation for the new Google Play app signing method

Simplier explanation for the new Google Play app signing method

I currently have an android project which is already enrolled to the new app signing method and uploaded to market by someone else

58