0

我正在尝试向我添加标题,listView但在活动启动时我只看到黑屏

public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.maincoverflow);

        final ListView itemslist = (ListView)findViewById(R.id.itemslist);        
        LayoutInflater inflater = getLayoutInflater();
        ViewGroup mTop = (ViewGroup)inflater.inflate(R.layout.main_header, itemslist, false);
        itemslist.addHeaderView(mTop, null, false);

        //some actions with header and list items
        //example: coverflow_item_title is located in header(R.layout.main_header)
        title = (TextView)findViewById(R.id.coverflow_item_title); //checked - is not null

        CoverFlow coverFlow =  (CoverFlow) findViewById(R.id.coverflow);
        ImageAdapter coverImageAdapter =  new ImageAdapter(this);
        coverFlow.setAdapter(new ImageAdapter(this));
        coverImageAdapter.createImages();

        coverFlow.setAdapter(coverImageAdapter);  
        coverFlow.setOnItemSelectedListener(new CoverAdapterView.OnItemSelectedListener(){           
           ...
           adapter = new LazyAdapter(MainCoverflowActivity.this, tools, tools_images);
           itemslist.setAdapter(adapter); 
        }

        itemslist.setOnItemClickListener(new AdapterView.OnItemClickListener() {
               ...
        }
}

maincoverflow.xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <ListView
        android:id="@+id/itemslist"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent" >
    </ListView>

</LinearLayout>

main_header.xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical" >

    <TextView
        android:id="@+id/coverflow_item_title"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:textAppearance="?android:attr/textAppearanceMedium" />

    <com.thumbsupstudio.mobitour.CoverFlow
        android:id="@+id/coverflow"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"/>

    <ImageView
        android:id="@+id/shadowbox"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:src="@drawable/shadow_box" />

</LinearLayout>

您可能会注意到我正在使用Coverflow小部件(从这里http://www.inter-fuser.com/2010/01/android-coverflow-widget.html) - 它工作正常。

一般来说,我会在更改项目listView时更改内容Coverflow。它工作正常,但我需要Coverflow滚动listView,所以我决定将它附加到标题。在那之后,屏幕上没有,一切都是黑色的listViewCoverflow

4

2 回答 2

0
try this

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayoutxmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >
<RelativeLayout
        android:id="@+id/headerLayout"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"/>
<TextView
        android:id="@+id/coverflow_item_title"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:textAppearance="?android:attr/textAppearanceMedium" />

    <com.thumbsupstudio.mobitour.CoverFlow
        android:id="@+id/coverflow"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"/>

    <ImageView
        android:id="@+id/shadowbox"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:src="@drawable/shadow_box" />

</RelativeLayout>


    <ListView
        android:id="@+id/itemslist"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent" >
    </ListView>

</RelativeLayout>
于 2012-04-11T10:24:59.187 回答
0

我找到了解决方案。我不完全理解为什么,但是:

不正确

init listView
inflate header and add it to the list
set list adapter in Coverflow onItemSelected handler (it launch automatically with item position=0)

正确的

init listView
inflate header and add it to the list
set any adapter to listView (!!!)
set listView adapter in Coverflow onItemSelected handler (it launch automatically with item position=0)

活动启动后具有在 Coverflow处理程序listView中设置的适配器内容。onItemSelected什么是第一个适配器分配 - 我不明白。

于 2012-04-11T11:30:22.947 回答