Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/19.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/4/jsp/3.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向合并适配器添加相对视图_Android_Adapter_Commonsware Cwac - Fatal编程技术网

Android向合并适配器添加相对视图

Android向合并适配器添加相对视图,android,adapter,commonsware-cwac,Android,Adapter,Commonsware Cwac,您好,我正在尝试向合并适配器添加相对视图,但它当前正在单独滚动到列表中,所以有人知道我如何向合并适配器添加带有图像视图和文本视图的相对布局吗 我的目标是让它看起来像这样 header(relativelyout red bar and title); List header(relativelyout red bar and title); List header(relativelyout red bar and title); List 让这一切滚动起来,就好像它是一个列表 这是我迄今为止

您好,我正在尝试向合并适配器添加相对视图,但它当前正在单独滚动到列表中,所以有人知道我如何向合并适配器添加带有图像视图和文本视图的相对布局吗

我的目标是让它看起来像这样

header(relativelyout red bar and title);
List
header(relativelyout red bar and title);
List
header(relativelyout red bar and title);
List
让这一切滚动起来,就好像它是一个列表

这是我迄今为止的尝试

 arrayAdapter = new ArrayAdapter<String>(this, R.layout.single_item, newsList);
    arrayAdapter2 = new ArrayAdapter<String>(this, R.layout.single_item, newsList2);
    arrayAdapter3 = new ArrayAdapter<String>(this, R.layout.single_item, newsList3);


        ListView list = getListView();
           list.setTextFilterEnabled(true);

           LayoutInflater inflater = (LayoutInflater) this.getSystemService(Context.LAYOUT_INFLATER_SERVICE );
            View header = inflater.inflate( R.layout.redcell, list, false);


    setListAdapter (arrayAdapter);


        adapter = new MergeAdapter();
        adapter.addView(header);
        adapter.addAdapter(arrayAdapter);
        adapter.addView(header);
        adapter.addAdapter(arrayAdapter2);
        adapter.addView(header);
        adapter.addAdapter(arrayAdapter3);
        setListAdapter(adapter);

    }   
arrayAdapter=新的arrayAdapter(这个,R.layout.single_项目,新闻列表);
arrayAdapter2=新的ArrayAdapter(此,R.layout.single_项,新闻列表2);
arrayAdapter3=新的ArrayAdapter(此,R.layout.single_项,新闻列表3);
ListView list=getListView();
list.setTextFilterEnabled(true);
LayoutInflater充气器=(LayoutInflater)this.getSystemService(Context.LAYOUT\u充气器\u服务);
视图标题=充气机。充气(R.layout.redcell,list,false);
setListAdapter(arrayAdapter);
adapter=新的MergeAdapter();
adapter.addView(头文件);
adapter.addAdapter(arrayAdapter);
adapter.addView(头文件);
adapter.addAdapter(arrayAdapter2);
adapter.addView(头文件);
adapter.addAdapter(arrayAdapter3);
setListAdapter(适配器);
}   
redcell.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:orientation="vertical"
     android:id="@+id/redcelllayout" >



    <ImageView
        android:id="@+id/imageView1"
        android:layout_width="match_parent"
        android:layout_height="30dp"
        android:src="@drawable/titlerect" />

    <TextView
        android:id="@+id/redheadertext"
        android:layout_width="match_parent"
        android:layout_height="30dp"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:gravity="left"
        android:paddingLeft="15dp"
        android:paddingTop="3dp"
        android:textColor="@color/white"
        android:textSize="15dp"
        android:textStyle="bold"/>




</RelativeLayout>

将每个列表的
布局高度设置为
包装内容
,并将所有内容包装在
滚动视图中


如果您可以将标题作为适配器本身的一部分作为分隔符,并使用单个列表而不是3个列表,那么可能会更容易。

与其在程序中创建标题,不如为该视图创建一个xml文件,将其膨胀,然后将其添加到适配器中

像这样:

LayoutInflater inflater = (LayoutInflater) this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

View header1 = inflater.inflate(R.layout.redbar_title);
View header2 = inflater.inflate(R.layout.redbar_title);
View header3 = inflater.inflate(R.layout.redbar_title);

adapter = new MergeAdapter();
adapter.addView(header1);
adapter.addAdapter(arrayAdapter);
adapter.addView(header2);
adapter.addAdapter(arrayAdapter2);
adapter.addView(header3);
adapter.addAdapter(arrayAdapter3);
setListAdapter(adapter);

它不允许我这样做,因为它不喜欢滚动视图中的列表,因为列表已经滚动了。你说“它不允许我这样做”是什么意思?如果您将高度设置为
wrap_content
,则列表将不会滚动,因为它将足够大以显示其所有项目。这是有道理的,但是我在Eclipse Under getLayoutInflator或其teling me中出错,要为itOh创建局部变量,您需要声明LayoutInflater的一个实例。编辑了我的答案。看一看。嗨,我已经这样做了,它仍然会将标题单独滚动到列表中,这样标题栏就会显示出来,并重新显示到顶部,等等,我已经修改了上面的代码,希望它能更清晰一点,因为我不知道是什么导致了它。此外,只有一个标题显示您是否删除了这一行
setListAdapter(arrayAdapter)?这可能会给你带来麻烦。。。将两个适配器设置为同一个列表…谢谢这就是我想要的效果现在唯一的问题是header2出现在第二个列表的下面,而不是上面