user3078406
user3078406

Reputation: 511

ListView check box does not check upon selection

The following code stops working when I add an if else statement. The commented code works when uncommented, but adding the if statement does not show the "Checked" in the listview item. Any help would be greatly appreciated.

public void onListItemClick(ListView parent, View view,int position,long id){

    //Toast.makeText(this, events[position] + " Alarm Set ",Toast.LENGTH_LONG).show();
    if(view!=null){
        Toast.makeText(this, events[position] + "Invalid email",Toast.LENGTH_LONG).show();
    }else{
        Toast.makeText(this, events[position] +"Please check your email!",Toast.LENGTH_LONG).show();

    }
}

Upvotes: 1

Views: 42

Answers (1)

basic
basic

Reputation: 3408

You need to use this:

if(listView.isItemChecked(position)){
 //logic
}else{
 //other logic
}

Upvotes: 1

Related Questions