0

I have a problem towards of calculating percentage of checked checkbox. My situation is, i have list of checkbox. after user press any checkbox, user should press calculate button. this calculate button will show another activity and also display percentage of checked checkbox. Can anyone help me?

percentage = (checked/total checkbox)*100
tarzanbappa
  • 4,930
  • 22
  • 75
  • 117
Miss A
  • 49
  • 1
  • 1
  • 4
  • Check this link. It will solve your problem. http://stackoverflow.com/questions/17070082/how-would-i-calculate-percentage-of-checkboxes-clicked – KishuDroid Sep 18 '15 at 04:39
  • i already try it, but the app stopped when click calculate button.. : – Miss A Sep 18 '15 at 05:01
  • can you please provide logcat for the same – KishuDroid Sep 18 '15 at 06:04
  • at com.example.sze.mutabaah.ChecklistActivity.percentageChecked(ChecklistActivity.java:170) at com.example.sze.mutabaah.ChecklistActivity$1.onClick(ChecklistActivity.java:62) at android.view.View.performClick(View.java:4478) at android.view.View$PerformClick.run(View.java:18698) at android.os.Handler.handleCallback(Handler.java:733) at android.os.Handler.dispatchMessage(Handler.java:95) at android.os.Looper.loop(Looper.java:149) – Miss A Sep 18 '15 at 06:54
  • cont: at android.app.ActivityThread.main(ActivityThread.java:5257) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:515) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:609) at dalvik.system.NativeStart.main(Native Method) – Miss A Sep 18 '15 at 06:54
  • hi, i cannot give all of the logcat because its too long. i will post it half by half – Miss A Sep 18 '15 at 07:15
  • 09-18 15:10:22.509 31129-31129/com.example.sze.mutabaah I/dalvikvm﹕ Could not find method android.content.res.TypedArray.getChangingConfigurations, referenced from method android.support.v7.internal.widget.TintTypedArray.getChangingConfigurations 09-18 15:10:22.509 31129-31129/com.example.sze.mutabaah W/dalvikvm﹕ VFY: unable to resolve virtual method 410: Landroid/content/res/TypedArray;.getChangingConfigurations ()I – Miss A Sep 18 '15 at 07:15
  • 09-18 15:10:22.509 31129-31129/com.example.sze.mutabaah D/dalvikvm﹕ VFY: replacing opcode 0x6e at 0x0002 09-18 15:10:22.509 31129-31129/com.example.sze.mutabaah I/dalvikvm﹕ Could not find method android.content.res.TypedArray.getType, referenced from method android.support.v7.internal.widget.TintTypedArray.getType 09-18 15:10:22.509 31129-31129/com.example.sze.mutabaah W/dalvikvm﹕ VFY: unable to resolve virtual method 432: Landroid/content/res/TypedArray;.getType (I)I – Miss A Sep 18 '15 at 07:16
  • 09-18 15:10:22.509 31129-31129/com.example.sze.mutabaah D/dalvikvm﹕ VFY: replacing opcode 0x6e at 0x0002 09-18 15:10:22.589 31129-31129/com.example.sze.mutabaah D/dalvikvm﹕ GC_FOR_ALLOC freed 189K, 2% free 12116K/12344K, paused 3ms, total 3ms 09-18 15:10:22.599 31129-31129/com.example.sze.mutabaah I/dalvikvm-heap﹕ Grow heap (frag case) to 17.361MB for 5760016-byte allocation 09-18 15:10:22.609 31129-31138/com.example.sze.mutabaah D/dalvikvm﹕ GC_FOR_ALLOC freed 5K, 2% free 17735K/17972K, paused 3ms, total 3ms – Miss A Sep 18 '15 at 07:16
  • 09-18 15:10:22.759 31129-31129/com.example.sze.mutabaah E/IMGSRV﹕ :0: PVRDRMOpen: TP3, ret = 46 09-18 15:10:22.769 31129-31129/com.example.sze.mutabaah E/IMGSRV﹕ :0: PVRDRMOpen: TP3, ret = 49 09-18 15:10:22.769 31129-31129/com.example.sze.mutabaah E/IMGSRV﹕ :0: PVRDRMOpen: TP3, ret = 50 09-18 15:10:22.769 31129-31129/com.example.sze.mutabaah E/IMGSRV﹕ :0: PVRDRMOpen: TP3, ret = 50 09-18 15:10:22.769 31129-31129/com.example.sze.mutabaah E/IMGSRV﹕ :0: PVRDRMOpen: TP3, ret = 50 09-18 15:10:22.779 31129-31129/com.example.sze.mutabaah E/IMGSRV﹕ :0: PVRDRMOpen: TP3, ret = 52 – Miss A Sep 18 '15 at 07:17
  • 09-18 15:10:22.799 31129-31129/com.example.sze.mutabaah D/OpenGLRenderer﹕ Enabling debug mode 0 09-18 15:12:22.589 31757-31757/com.example.sze.mutabaah I/dalvikvm﹕ Could not find method android.content.res.TypedArray.getChangingConfigurations, referenced from method android.support.v7.internal.widget.TintTypedArray.getChangingConfigurations 09-18 15:12:22.589 31757-31757/com.example.sze.mutabaah W/dalvikvm﹕ VFY: unable to resolve virtual method 410: Landroid/content/res/TypedArray;.getChangingConfigurations ()I – Miss A Sep 18 '15 at 07:17
  • 09-18 15:12:22.589 31757-31757/com.example.sze.mutabaah D/dalvikvm﹕ VFY: replacing opcode 0x6e at 0x0002 09-18 15:12:22.589 31757-31757/com.example.sze.mutabaah I/dalvikvm﹕ Could not find method android.content.res.TypedArray.getType, referenced from method android.support.v7.internal.widget.TintTypedArray.getType 09-18 15:12:22.589 31757-31757/com.example.sze.mutabaah W/dalvikvm﹕ VFY: unable to resolve virtual method 432: Landroid/content/res/TypedArray;.getType (I)I 09-18 15:12:22.589 31757-31757/com.example.sze.mutabaah D/dalvikvm﹕ VFY: replacing opcode 0x6e at 0x0002 – Miss A Sep 18 '15 at 07:18
  • 09-18 15:12:22.739 31757-31757/com.example.sze.mutabaah D/dalvikvm﹕ GC_FOR_ALLOC freed 168K, 2% free 12115K/12324K, paused 4ms, total 4ms 09-18 15:12:22.749 31757-31757/com.example.sze.mutabaah I/dalvikvm-heap﹕ Grow heap (frag case) to 17.360MB for 5760016-byte allocation 09-18 15:12:22.759 31757-31766/com.example.sze.mutabaah D/dalvikvm﹕ GC_FOR_ALLOC freed 5K, 2% free 17735K/17952K, paused 5ms, total 5ms 09-18 15:12:22.929 31757-31757/com.example.sze.mutabaah E/IMGSRV﹕ :0: PVRDRMOpen: TP3, ret = 46 – Miss A Sep 18 '15 at 07:18
  • 09-18 15:12:22.939 31757-31757/com.example.sze.mutabaah E/IMGSRV﹕ :0: PVRDRMOpen: TP3, ret = 49 09-18 15:12:22.939 31757-31757/com.example.sze.mutabaah E/IMGSRV﹕ :0: PVRDRMOpen: TP3, ret = 50 09-18 15:12:22.939 31757-31757/com.example.sze.mutabaah E/IMGSRV﹕ :0: PVRDRMOpen: TP3, ret = 50 09-18 15:12:22.939 31757-31757/com.example.sze.mutabaah E/IMGSRV﹕ :0: PVRDRMOpen: TP3, ret = 50 09-18 15:12:22.949 31757-31757/com.example.sze.mutabaah E/IMGSRV﹕ :0: PVRDRMOpen: TP3, ret = 52 09-18 15:12:22.969 31757-31757/com.example.sze.mutabaah D/OpenGLRenderer﹕ Enabling debug mode 0 – Miss A Sep 18 '15 at 07:19
  • 09-18 15:12:43.769 31757-31757/com.example.sze.mutabaah D/AndroidRuntime﹕ Shutting down VM 09-18 15:12:43.769 31757-31757/com.example.sze.mutabaah W/dalvikvm﹕ threadid=1: thread exiting with uncaught exception (group=0x430f3140) 09-18 15:12:43.779 31757-31757/com.example.sze.mutabaah E/AndroidRuntime﹕ FATAL EXCEPTION: main Process: com.example.sze.mutabaah, PID: 31757 java.lang.NullPointerException at com.example.sze.mutabaah.ChecklistActivity.percentageChecked(ChecklistActivity.java:170) – Miss A Sep 18 '15 at 07:19
  • at com.example.sze.mutabaah.ChecklistActivity$1.onClick(ChecklistActivity.java:62) at android.view.View.performClick(View.java:4478) at android.view.View$PerformClick.run(View.java:18698) at android.os.Handler.handleCallback(Handler.java:733) at android.os.Handler.dispatchMessage(Handler.java:95) at android.os.Looper.loop(Looper.java:149) at android.app.ActivityThread.main(ActivityThread.java:5257) at java.lang.reflect.Method.invokeNative(Native Method) – Miss A Sep 18 '15 at 07:19
  • at java.lang.reflect.Method.invoke(Method.java:515) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:609) at dalvik.system.NativeStart.main(Native Method) – Miss A Sep 18 '15 at 07:20
  • 09-18 15:13:17.779 31757-31757/com.example.sze.mutabaah I/Process﹕ Sending signal. PID: 31757 SIG: 9 09-18 15:13:17.889 31914-31914/com.example.sze.mutabaah D/dalvikvm﹕ Late-enabling CheckJNI 09-18 15:13:17.889 31914-31914/com.example.sze.mutabaah D/dalvikvm﹕ Try to disable coredump for pid 31914 09-18 15:13:17.889 31914-31914/com.example.sze.mutabaah D/dalvikvm﹕ Process 31914 nice name: com.example.sze.mutabaah – Miss A Sep 18 '15 at 07:20
  • 09-18 15:13:17.889 31914-31914/com.example.sze.mutabaah D/dalvikvm﹕ Extra Options: not specified 09-18 15:13:17.989 31914-31914/com.example.sze.mutabaah I/dalvikvm﹕ Could not find method android.content.res.TypedArray.getChangingConfigurations, referenced from method android.support.v7.internal.widget.TintTypedArray.getChangingConfigurations 09-18 15:13:17.989 31914-31914/com.example.sze.mutabaah W/dalvikvm﹕ VFY: unable to resolve virtual method 410: Landroid/content/res/TypedArray;.getChangingConfigurations ()I – Miss A Sep 18 '15 at 07:20
  • 09-18 15:13:17.989 31914-31914/com.example.sze.mutabaah D/dalvikvm﹕ VFY: replacing opcode 0x6e at 0x0002 09-18 15:13:17.989 31914-31914/com.example.sze.mutabaah I/dalvikvm﹕ Could not find method android.content.res.TypedArray.getType, referenced from method android.support.v7.internal.widget.TintTypedArray.getType 09-18 15:13:17.989 31914-31914/com.example.sze.mutabaah W/dalvikvm﹕ VFY: unable to resolve virtual method 432: Landroid/content/res/TypedArray;.getType (I)I 09-18 15:13:17.989 31914-31914/com.example.sze.mutabaah D/dalvikvm﹕ VFY: replacing opcode 0x6e at 0x0002 – Miss A Sep 18 '15 at 07:20
  • 09-18 15:13:18.079 31914-31914/com.example.sze.mutabaah D/dalvikvm﹕ GC_FOR_ALLOC freed 193K, 2% free 12116K/12348K, paused 3ms, total 3ms 09-18 15:13:18.089 31914-31914/com.example.sze.mutabaah I/dalvikvm-heap﹕ Grow heap (frag case) to 17.361MB for 5760016-byte allocation 09-18 15:13:18.089 31914-31923/com.example.sze.mutabaah D/dalvikvm﹕ GC_FOR_ALLOC freed 5K, 2% free 17735K/17976K, paused 3ms, total 3ms 09-18 15:13:18.239 31914-31914/com.example.sze.mutabaah E/IMGSRV﹕ :0: PVRDRMOpen: TP3, ret = 46 – Miss A Sep 18 '15 at 07:21
  • 09-18 15:13:18.239 31914-31914/com.example.sze.mutabaah E/IMGSRV﹕ :0: PVRDRMOpen: TP3, ret = 49 09-18 15:13:18.239 31914-31914/com.example.sze.mutabaah E/IMGSRV﹕ :0: PVRDRMOpen: TP3, ret = 50 09-18 15:13:18.249 31914-31914/com.example.sze.mutabaah E/IMGSRV﹕ :0: PVRDRMOpen: TP3, ret = 50 09-18 15:13:18.249 31914-31914/com.example.sze.mutabaah E/IMGSRV﹕ :0: PVRDRMOpen: TP3, ret = 50 09-18 15:13:18.249 31914-31914/com.example.sze.mutabaah E/IMGSRV﹕ :0: PVRDRMOpen: TP3, ret = 52 – Miss A Sep 18 '15 at 07:21
  • 09-18 15:13:18.279 31914-31914/com.example.sze.mutabaah D/OpenGLRenderer﹕ Enabling debug mode 0 09-18 15:13:27.839 31958-31958/com.example.sze.mutabaah I/dalvikvm﹕ Could not find method android.content.res.TypedArray.getChangingConfigurations, referenced from method android.support.v7.internal.widget.TintTypedArray.getChangingConfigurations 09-18 15:13:27.839 31958-31958/com.example.sze.mutabaah W/dalvikvm﹕ VFY: unable to resolve virtual method 410: Landroid/content/res/TypedArray;.getChangingConfigurations ()I – Miss A Sep 18 '15 at 07:22
  • 09-18 15:13:27.839 31958-31958/com.example.sze.mutabaah D/dalvikvm﹕ VFY: replacing opcode 0x6e at 0x0002 09-18 15:13:27.839 31958-31958/com.example.sze.mutabaah I/dalvikvm﹕ Could not find method android.content.res.TypedArray.getType, referenced from method android.support.v7.internal.widget.TintTypedArray.getType 09-18 15:13:27.839 31958-31958/com.example.sze.mutabaah W/dalvikvm﹕ VFY: unable to resolve virtual method 432: Landroid/content/res/TypedArray;.getType (I)I – Miss A Sep 18 '15 at 07:22
  • 09-18 15:13:27.839 31958-31958/com.example.sze.mutabaah D/dalvikvm﹕ VFY: replacing opcode 0x6e at 0x0002 09-18 15:13:27.929 31958-31958/com.example.sze.mutabaah D/dalvikvm﹕ GC_FOR_ALLOC freed 197K, 2% free 12115K/12352K, paused 2ms, total 2ms 09-18 15:13:27.939 31958-31958/com.example.sze.mutabaah I/dalvikvm-heap﹕ Grow heap (frag case) to 17.360MB for 5760016-byte allocation – Miss A Sep 18 '15 at 07:22
  • 09-18 15:13:27.949 31958-31967/com.example.sze.mutabaah D/dalvikvm﹕ GC_FOR_ALLOC freed 5K, 2% free 17735K/17980K, paused 5ms, total 5ms 09-18 15:13:28.129 31958-31958/com.example.sze.mutabaah E/IMGSRV﹕ :0: PVRDRMOpen: TP3, ret = 46 09-18 15:13:28.149 31958-31958/com.example.sze.mutabaah E/IMGSRV﹕ :0: PVRDRMOpen: TP3, ret = 49 09-18 15:13:28.149 31958-31958/com.example.sze.mutabaah E/IMGSRV﹕ :0: PVRDRMOpen: TP3, ret = 50 09-18 15:13:28.149 31958-31958/com.example.sze.mutabaah E/IMGSRV﹕ :0: PVRDRMOpen: TP3, ret = 50 – Miss A Sep 18 '15 at 07:23
  • 09-18 15:13:28.149 31958-31958/com.example.sze.mutabaah E/IMGSRV﹕ :0: PVRDRMOpen: TP3, ret = 50 09-18 15:13:28.159 31958-31958/com.example.sze.mutabaah E/IMGSRV﹕ :0: PVRDRMOpen: TP3, ret = 52 09-18 15:13:28.169 31958-31958/com.example.sze.mutabaah D/OpenGLRenderer﹕ Enabling debug mode 0 09-18 15:13:48.309 31958-31958/com.example.sze.mutabaah D/AndroidRuntime﹕ Shutting down VM 09-18 15:13:48.309 31958-31958/com.example.sze.mutabaah W/dalvikvm﹕ threadid=1: thread exiting with uncaught exception (group=0x430f3140) – Miss A Sep 18 '15 at 07:23
  • 09-18 15:13:48.319 31958-31958/com.example.sze.mutabaah E/AndroidRuntime﹕ FATAL EXCEPTION: main Process: com.example.sze.mutabaah, PID: 31958 java.lang.NullPointerException at com.example.sze.mutabaah.ChecklistActivity.percentageChecked(ChecklistActivity.java:170) at com.example.sze.mutabaah.ChecklistActivity$1.onClick(ChecklistActivity.java:62) at android.view.View.performClick(View.java:4478) at android.view.View$PerformClick.run(View.java:18698) – Miss A Sep 18 '15 at 07:23
  • at android.os.Handler.handleCallback(Handler.java:733) at android.os.Handler.dispatchMessage(Handler.java:95) at android.os.Looper.loop(Looper.java:149) at android.app.ActivityThread.main(ActivityThread.java:5257) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:515) at com.android.internal.os.ZygoteInit – Miss A Sep 18 '15 at 07:24
  • $MethodAndArgsCaller.run(ZygoteInit.java:793) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:609) at dalvik.system.NativeStart.main(Native Method) – Miss A Sep 18 '15 at 07:24
  • ---------------------------------------- – Miss A Sep 18 '15 at 07:24
  • 1
    you can edit your answer instead of commenting this much code – KishuDroid Sep 18 '15 at 07:28

1 Answers1

0

In Activity1,

Intent i = new Intent(getApplicationContext(), activity2.class);
i.putExtra("key", chkbox1.getText()); //pass chkbox1 value to another activity
startActivity(i);

In Activity2,

String chkbox1=getIntent().getExtras().getString("key");
kris ho
  • 51
  • 1
  • 9