Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/233.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/list/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在Android中使用带有可扩展列表的ImageView?_Android_List_View_Expandable - Fatal编程技术网

如何在Android中使用带有可扩展列表的ImageView?

如何在Android中使用带有可扩展列表的ImageView?,android,list,view,expandable,Android,List,View,Expandable,我在android中有一个可扩展的列表,我可以很容易地用字符串填充它,但是现在我想在列表的每一行添加一个可绘制的列表(每一行上有一个不同的列表),用我已有的代码最简单的方法是什么?谢谢 public class Physical extends ExpandableListActivity { public static final int GROUPS = 1; public SimpleExpandableListAdapter expListAdapter; private boolean

我在android中有一个可扩展的列表,我可以很容易地用字符串填充它,但是现在我想在列表的每一行添加一个可绘制的列表(每一行上有一个不同的列表),用我已有的代码最简单的方法是什么?谢谢

public class Physical extends ExpandableListActivity {
public static final int GROUPS = 1;
public SimpleExpandableListAdapter expListAdapter;
private boolean expanded = true;

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.phys_sub); 

    String [] cats = { "phy1", "phys2" };

    List<Map<String, String>> groupData = new ArrayList<Map<String, String>>();
    List<List<Map<String, String>>> childData = new ArrayList<List<Map<String, String>>>();
    for (int i = 0; i < GROUPS; i++) {
        Map<String, String> curGroupMap = new HashMap<String, String>();
        groupData.add(curGroupMap);
        curGroupMap.put( "group", "Categories" );

        List<Map<String, String>> children = new ArrayList<Map<String, String>>();
        for( int n = 0 ; n < cats.length ; n++ ) {
            Map<String, String> curChildMap = new HashMap<String, String>();
            curChildMap.put( "child", cats[n] );
            children.add(curChildMap);
        }
        childData.add(children);
    }

    expListAdapter =
            new SimpleExpandableListAdapter(
                    /* context */
                    this,
                    /* creates Group list */
                    groupData, 
                    /*Group item layout XML */
                    R.layout.group_row,    
                    /* the key of each group element (not child's) */
                    new String[] { "group" },
                    /* data under the key goes into this TextView */
                    new int[] { R.id.group_text }, 
                    /* creates Child List (sub-level entries) */
                    childData,
                    /* layout for children in list */
                    R.layout.child_sub,
                    /* the key of each child element */
                    new String[] { "child" },
                    /* data under the child keys go into this textView */
                    new int[] { R.id.child_text }
                );
            /* sets up and initializes the adapter for the list */
            setListAdapter(expListAdapter);

            getExpandableListView().setOnGroupExpandListener( new OnGroupExpandListener() {
                 public void onGroupExpand(int groupPosition) {
                     expanded = true;
                   }
               });
            getExpandableListView().setOnGroupCollapseListener( new OnGroupCollapseListener() {
                public void onGroupCollapse(int groupPosition) {
                    expanded = false;
                }
            });
            if (expanded != false ) {
                getExpandableListView().expandGroup(0);
            }
}
public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, final int childPosition, long id) {
    switch (childPosition) {
    case 0:
        Intent spine_plus_intent = new Intent(Physical.this, SpinePlus.class);
        startActivity(spine_plus_intent);
        finish();
        break;
    }
    return true;
}
公共类物理扩展ExpandableListActivity{
公共静态最终整数组=1;
公共SimpleExpandableListAdapter解释适配器;
私有布尔扩展=真;
/**在首次创建活动时调用*/
@凌驾
创建时的公共void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.phys_sub);
字符串[]cats={“phy1”,“phys2”};
List groupData=new ArrayList();
List childData=new ArrayList();
对于(int i=0;i

}

您需要定义一个自定义的可扩展列表适配器,并重新定义getchildview/getgroupview

从这里开始,您有两条路要走:一条,您可以通过编程方式将ImageView添加到子/组视图中(我不鼓励您使用这种方法),或者为子/组视图定义一个xml布局文件并将其膨胀(可能还可以动态编辑内容)


简单的适配器不够灵活,无法实现良好的效果。尤其是当您需要为其图元创建自定义视图时。(更不用说可伸缩性:始终规划和编写代码,记住您的需求在未来可能会扩大,灵活的基础允许更多的自由度,并防止您划伤太多的代码)

,你绝对确定地图列表是处理数据的正确方法吗?你知道有什么好的网站可以让我学习如何使用自定义适配器吗?试试这个:不管怎样,只要谷歌“自定义适配器列表android”,你就会没事了。