唯一标识android复合视图中的元素

唯一标识android复合视图中的元素,android,android-custom-view,Android,Android Custom View,问题:如何唯一识别android复合视图中的元素 背景: 在我的应用程序中,我使用了复合视图。因为它有两个文本字段,每行一个图像和一个搜索栏。布局很好 因此,在布局中有两个单独的搜索栏。我需要在我的活动中得到它们的价值 我可以分别识别每一行,因为它们有id。但行中的项目在每一行中重复 我的问题是 如何唯一地识别每个搜索栏? row_layout.xml <?xml version="1.0" encoding="utf-8"?> <merge xmlns:android="ht

问题:如何唯一识别android复合视图中的元素

背景: 在我的应用程序中,我使用了复合视图。因为它有两个文本字段,每行一个图像和一个搜索栏。布局很好

因此,在布局中有两个单独的搜索栏。我需要在我的活动中得到它们的价值

我可以分别识别每一行,因为它们有id。但行中的项目在每一行中重复

我的问题是 如何唯一地识别每个搜索栏?

row_layout.xml

<?xml version="1.0" encoding="utf-8"?>
<merge xmlns:android="http://schemas.android.com/apk/res/android" >

       <RelativeLayout
            android:id="@+id/colunm"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:paddingTop="40sp" >

            <ImageView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:layout_marginLeft="6dip"
                android:layout_marginRight="6dip"/>

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:ellipsize="marquee"
                android:fadingEdge="horizontal"
                android:singleLine="true"
                android:textAppearance="?android:attr/textAppearanceMedium" />

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:ellipsize="end"
                android:maxLines="1"
                android:textAppearance="?android:attr/textAppearanceSmall" />

            <SeekBar
                android:layout_width="fill_parent"
                android:layout_height="wrap_content" />
        </RelativeLayout>

    </merge>
<LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical" >


        <com.example.test.view.Compound
            android:id="@+id/vol_Row1"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            custom:column_summary="TEST SUMMARY I"
            custom:column_title="Test TITLE 1"
            custom:image_Icon="@drawable/ic_action1" />

        <com.example.test.view.Compound
            android:id="@+id/vol_Row2"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            custom:column_summary="TEST SUMMARY 2"
            custom:column_title="Test TITLE 2"
            custom:image_Icon="@drawable/ic_action2" />
    </LinearLayout>

首先,在XML布局文件中向seekbar添加一个ID

<SeekBar
            android:id="@+id/seek"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content" />

我是这样做的。在复合视图中,我为每个元素提供了唯一的ID。然后在测试代码中,我可以像这样唯一地访问它们

private View inflaterView;
    LayoutInflater i=(LayoutInflater) activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        inflaterView=i.inflate(R.layout.screen_layout, null);
        seekBar=(SeekBar) inflaterView.findViewById(R.id.vol_Row1).findViewById(R.id.seekbar);

您是否为row_布局创建了类?是的,我创建了。布局很好。但我需要分别识别每个元素。你们有什么想法吗?首先你们需要在你们的行布局中给你们的搜索棒id。。。然后在该行的类中创建getter以获取搜索栏值。这对你有帮助吗?或者您想要示例代码?但行中的seekbar布局在每行中重复。我还需要在这一行的类之外访问它们。这可能吗?你能给我一些示例代码吗?你可以发布你的row_layout类,这样我就可以为你编辑它了,这很容易。我用其他方法做了,稍后我会更新我的答案。顺便说一句,谢谢你的帮助。
Coumpund c1 = (Compound)findViewById(R.id.vol_Row1);
Coumpund c2 = (Compound)findViewById(R.id.vol_Row2);

SeekBar sb1 = (SeekBar)c1.findViewById(seek); // Gives you the SeekBar of c1
SeekBar sb2 = (SeekBar)c2.findViewById(seek); // Gives you the SeekBar of c2
private View inflaterView;
    LayoutInflater i=(LayoutInflater) activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        inflaterView=i.inflate(R.layout.screen_layout, null);
        seekBar=(SeekBar) inflaterView.findViewById(R.id.vol_Row1).findViewById(R.id.seekbar);