简体   繁体   中英

Spinner RecyclerView

This is Priyatham Suresh, I am new to android.

I am using spinner with RecyclerView. I have row which contains textView and spinner. I want to get the row position of a RecyclerView, when i select the spinner item.

I have used ListView intitially and used onItemSelected which is giving spinner item positon but unable to get row position.

here is my row table_settings_row.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="97dp"
    android:paddingTop="16dp"
    android:paddingBottom="16dp"
    android:id="@+id/relativeone">

    <TextView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:textAppearance="?android:attr/textAppearanceLarge"
        android:text="Table Number"
        android:id="@+id/tableNo_textview"
        android:layout_alignParentTop="true"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:layout_marginLeft="12dp"
        android:textStyle="bold"
        android:textColor="#ff7c40"
        android:editable="true" />

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_marginTop="30dp"
        android:paddingTop="10dp">
        <ImageView
            android:src="@drawable/ic_person"
            android:layout_width="22dp"
            android:layout_height="22dp"
            android:paddingLeft="10dp" />

        <Spinner
            android:layout_width="300dp"
            android:layout_height="wrap_content"
            android:id="@+id/users_spinner"
            android:entries="@array/sample_members"
            android:spinnerMode="dropdown"
            android:paddingLeft="20dp"/>
    </LinearLayout>

</RelativeLayout>
</LinearLayout>

Just, set tag(position) to spinner on OnBindView. Now, when you select spinner, you can get tag of that spinner, which is position you want.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM