<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent"> <ExpandableListView android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/elv_expandable" > </ExpandableListView> </LinearLayout>
public class ExpandableActivity extends AppCompatActivity { @Override protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_expandable); List<Map<String,String>> lm=new ArrayList<>(); List<List<Map<String,String>>> llm=new ArrayList<>(); for (int i = 0; i <3; i++) { Map<String,String> m=new HashMap<>(); m.put("test","分组"+i); lm.add(m); List<Map<String,String>> l=new ArrayList<>(); for (int j = 0; j <3; j++) { Map<String,String> h=new HashMap<>(); h.put("test","第"+i+"组第"+j+"个"); l.add(h); } llm.add(l); } SimpleExpandableListAdapter ela=new SimpleExpandableListAdapter(this,lm,android.R.layout.simple_list_item_1,new String[]{"test"},new int[]{android.R.id.text1},llm,android.R.layout.simple_list_item_1,new String[]{"test"},new int[]{android.R.id.text1}); ExpandableListView elv= (ExpandableListView) findViewById(R.id.elv_expandable); elv.setAdapter(ela); } }
android 实现A、B、C分组可点击
最新推荐文章于 2021-12-08 14:17:13 发布