-1

I have an app where I have some linear layouts--(first_linear,second_linear,third_linear,fourth_linear). In each linear layout there are different items--

(i) an edittext and an image button (ii)a textView and a spinner (iii)two textViews (iv) two textViews

 <LinearLayout
        android:id="@+id/first_linear"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:layout_constraintHorizontal_bias="0.502"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        android:layout_marginTop="50dp">



        <EditText
            android:id="@+id/editTaskName"
            android:layout_width="0dp"
            android:layout_weight="6"
            android:layout_height="wrap_content"
            android:hint="@string/entName"
            android:inputType="textPersonName"

            />

        <ImageButton

            android:background="@drawable/button_background"
            android:id="@+id/micro_phone"
            android:layout_width="0dp"
            android:layout_weight="1"
            android:src="@drawable/ic_mic_black_24dp"
            android:layout_height="match_parent" />
    </LinearLayout>


    <LinearLayout
        android:id="@+id/second_linear"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:layout_constraintHorizontal_bias="0.502"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="@id/first_linear"
        android:layout_marginTop="50dp">

        <TextView
            android:textSize="20dp"
            android:textColor="#000000"
            android:id="@+id/typeEntry"
            android:text="Type"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_marginLeft="20dp"
            android:layout_marginTop="40dp"
            android:layout_weight="1"/>

        <Spinner
            android:id="@+id/spnTaskType"
            android:layout_width="0dp"
            android:layout_weight="2"
            android:layout_height="wrap_content"
            android:layout_marginTop="40dp"

            />
    </LinearLayout>

    <LinearLayout
        android:id="@+id/third_linear"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:layout_constraintHorizontal_bias="0.502"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="@id/second_linear"
        android:layout_marginTop="60dp">

        <TextView
            android:textSize="20dp"
            android:textColor="#000000"
            android:id="@+id/DateEntry"
            android:text="Date"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_marginLeft="20dp"
            android:layout_marginTop="40dp"
            android:layout_weight="1"/>

        <TextView
            android:id="@+id/txttvDate"
            android:layout_width="0dp"
            android:layout_weight="2"
            android:layout_height="wrap_content"
            android:layout_marginTop="56dp"
            android:onClick="edittxtDate"
            android:textAlignment="center"
            android:textAppearance="@android:style/TextAppearance.Large"
            />

    </LinearLayout>

    <LinearLayout
        android:id="@+id/fourth_linear"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:layout_constraintHorizontal_bias="0.502"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="@id/third_linear"
        android:layout_marginTop="60dp">

        <TextView
            android:textColor="#000000"
            android:textSize="20dp"
            android:id="@+id/TimeEntry"
            android:text="Time"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_marginLeft="20dp"
            android:layout_marginTop="40dp"
            android:layout_weight="1"/>
        <TextView
            android:id="@+id/txtvTime"
            android:layout_width="0dp"
            android:layout_weight="2"
            android:layout_height="wrap_content"
            android:layout_marginTop="40dp"
            android:onClick="edittxtTime"
            android:textAlignment="center"
            android:textAppearance="@android:style/TextAppearance.Large" />
    </LinearLayout>

But now I want to keep those linear layouts in a listView. How can I do that? Should I use baseAdapter or arrayAdapter?

Thanks in advance!!

  • Could you post an image of what you expect to develop? – Marc Estrada May 25 '18 at 07:05
  • No need to put them in a listview. That'd be more work for nothing because you have 3 different items out of 4. If you really want to go that way then look into this: https://stackoverflow.com/questions/8166497/custom-adapter-for-list-view – denvercoder9 May 25 '18 at 07:07
  • Possible duplicate of [Custom Adapter for List View](https://stackoverflow.com/questions/8166497/custom-adapter-for-list-view) – denvercoder9 May 25 '18 at 07:07
  • 1
    You don't need to use a listview. use a scrollview instead to wrap them around the whole views. I'd suggest using a single `` and design the whole. Using too many linear layout is just bad coding. Also point to note can have only one direct child. – sanjeev May 25 '18 at 07:20
  • It you want to generate list then use `ListView` else `ScrollView` will do your work – sneharc May 25 '18 at 07:48
  • Should i use an int array containing ids or a linearlayout array? – sayanmanik_sm May 25 '18 at 07:49
  • -Create one adapter item layout and put all the components into linear layout in that xml. -after that according to your requirement set visibility of the xml file components. -and last step inflate this xml file into adapter and set this adapter to listview or recycleview. – Mahesh Keshvala May 25 '18 at 08:14

1 Answers1

1

If you are looking to just have the long list of controls scroll then use a scrollview.

<ScrollView
    android:layout_width="match_parent"
    android:layout_height="match_parent"

    <LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content">
        ... All your linear layouts here
    </LinearLayout>
</ScrollView>
CodeChimp
  • 4,745
  • 6
  • 45
  • 61