When I swipe my tab I want it to alert multi select checkbox but not when application starts.I want it to alert when I am in second tab.How to achieve this functionality? I wrote the following code in the second Tab but the alert pops up at the time of application start.
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_tab2, container, false);
final List<Integer> selectedItems = new ArrayList<Integer>();
String[] itemList = {"Item1", "Item2", "Item3"};
final AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
builder.setTitle("Multi Select");
builder.setMultiChoiceItems(itemList, null, new DialogInterface.OnMultiChoiceClickListener() {
@Override
public void onClick(DialogInterface dialog, int which, boolean isChecked) {
if (isChecked) {
selectedItems.add(which);
}
}
}).setPositiveButton("Ok", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
}
});
builder.show();
return view;
}
I solved the issue by keeping a button in the fragment and showing the alert dialog on click.