开发者

android: Custom (compund) control in ListView

I have a srange trouble wit the ListView: I've created the compound control

public class TopicControl extends LinearLayout
....

<merge xmlns:android="http://schemas.android.com/apk/res/android">
    <LinearLayout
        android:id="@+id/llTopicHeader"
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content"
    >
 开发者_如何学Go       <Button 
            android:id="@+id/btnTopicTitle"
            android:layout_width="wrap_content" 
            android:layout_height="wrap_content"
            android:tag="btnTopicTitle"
        ></Button>
        <LinearLayout
            android:id="@+id/llTopicBar"
            android:layout_width="wrap_content" 
            android:layout_height="wrap_content"
            android:visibility="invisible"
            android:tag="llTopicBar"
        >
            <Button
                android:layout_width="wrap_content" 
                android:layout_height="wrap_content"
                android:background="@drawable/bar_calendar"
            ></Button>
            <Button
                android:layout_width="wrap_content" 
                android:layout_height="wrap_content"
                android:background="@drawable/bar_person"
            ></Button>
        </LinearLayout>
    </LinearLayout>
    <TextView 
        android:id="@+id/tvTopicText"
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content"
    ></TextView>
</merge>

In that control I implemented hiding/showing llTopicBar on btnTopicTitle click.

The problem is that when I add that component to ListView, after pressing btnTopicTitle, llTopicBar becomes visible not only for the clicked item, but for every second LstViewItem.

after adding "parent" verification llTopicBar becomes visible for every 4th item in the ListView.

Override
public void onClick(View v)
{
    if (v.getParent().getParent() == getThis())
    llTopicBar.setVisibility(llTopicBar.getVisibility() == View.VISIBLE ? View.INVISIBLE : View.VISIBLE);
}

Could you please help me with that problem?


The problem was within reusing Views for ListView during scrolling.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜