import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.ActionMode;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.widget.AbsListView;
import android.widget.ExpandableListView;
import android.widget.ListView;
import android.widget.Toast;
import com.asite.adoddle.R;
import com.asite.adoddle.adapter.ExpandableAdapter;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
public class ExpandableActivity extends AppCompatActivity {
ExpandableListView expListView;
ExpandableAdapter listAdapter;
List<String> listDataHeader;
HashMap<String, List<String>> listDataChild;
//ListView listView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_expandable);
expListView = (ExpandableListView) findViewById(R.id.expandableListView);
/*listView = (ListView) findViewById(R.id.listView);
listView.setAdapter(new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,android.R.id.text1,new String[]{"A","B","C","D"}));
listView.setChoiceMode(ExpandableListView.CHOICE_MODE_MULTIPLE_MODAL);*/
prepareListData();
listAdapter = new ExpandableAdapter(this, listDataHeader, listDataChild);
// setting list adapter
expListView.setAdapter(listAdapter);
expListView.setChoiceMode(ExpandableListView.CHOICE_MODE_MULTIPLE_MODAL);
expListView.setMultiChoiceModeListener(new AbsListView.MultiChoiceModeListener() {
@Override
public void onItemCheckedStateChanged(ActionMode actionMode, int i, long l, boolean b) {
Toast.makeText(ExpandableActivity.this, i + " selected = "+b, Toast.LENGTH_SHORT).show();
}
@Override
public boolean onCreateActionMode(ActionMode actionMode, Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.addtoofflinemenu, menu);
return true;
}
@Override
public boolean onPrepareActionMode(ActionMode actionMode, Menu menu) {
return false;
}
@Override
public boolean onActionItemClicked(ActionMode actionMode, MenuItem menuItem) {
return false;
}
@Override
public void onDestroyActionMode(ActionMode actionMode) {
}
});
}
/*
* Preparing the list data
*/
private void prepareListData() {
listDataHeader = new ArrayList<String>();
listDataChild = new HashMap<String, List<String>>();
// Adding child data
listDataHeader.add("Top 250");
listDataHeader.add("Now Showing");
listDataHeader.add("Coming Soon..");
// Adding child data
List<String> top250 = new ArrayList<String>();
top250.add("The Shawshank Redemption");
top250.add("The Godfather");
top250.add("The Godfather: Part II");
top250.add("Pulp Fiction");
top250.add("The Good, the Bad and the Ugly");
top250.add("The Dark Knight");
top250.add("12 Angry Men");
List<String> nowShowing = new ArrayList<String>();
nowShowing.add("The Conjuring");
nowShowing.add("Despicable Me 2");
nowShowing.add("Turbo");
nowShowing.add("Grown Ups 2");
nowShowing.add("Red 2");
nowShowing.add("The Wolverine");
List<String> comingSoon = new ArrayList<String>();
comingSoon.add("2 Guns");
comingSoon.add("The Smurfs 2");
comingSoon.add("The Spectacular Now");
comingSoon.add("The Canyons");
comingSoon.add("Europa Report");
listDataChild.put(listDataHeader.get(0), top250); // Header, Child data
listDataChild.put(listDataHeader.get(1), nowShowing);
listDataChild.put(listDataHeader.get(2), comingSoon);
}
}
Вот мой код, чтобы включить режим действий в ExpandableListView. Когда я долго нажимаю на какой-либо элемент, тогда режим действия становится активным, но когда я выбираю какой-либо элемент, onItemCheckedStateChanged метод не вызывает.режим действия не работает в ExpandableListView в андроиде