I have created six dynamic Checkbox for my app and i want to Pop-up an AlertBox if the check box is checked but i am finding any result from my code. I am true value to the checkbox but no AlertBox is coming.
Java Code :
package com.example.mycheckbox;
import android.os.Bundle;
import android.app.Activity;
import android.app.AlertDialog;
import android.util.SparseBooleanArray;
import android.widget.CheckBox;
import android.widget.LinearLayout;
import android.widget.ListView;
public class MainActivity extends Activity
{
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
LinearLayout ll = (LinearLayout) findViewById(R.id.ii);
CheckBox[] cb = new CheckBox[6];
for (int i = 0; i < 6; i++)
{
cb[i] = new CheckBox(this);
cb[i].setText("Dynamic Checkbox " + i);
cb[i].setId(i + 6);
if (cb[i].isChecked())
{
AlertDialog.Builder myalert = new AlertDialog.Builder(this);
myalert.setTitle("Demo Title - "+i).setMessage(" Message from - "+i).setNeutralButton("Close", null).show();
}
ll.addView(cb[i]);
}
}
}
I want to pop an AlertDialog
for each CheckBox
if that is checked.