GithubHelp home page GithubHelp logo

Comments (3)

afohrman avatar afohrman commented on June 8, 2024

Hi @EnriekNP, thanks for filing! Could you please share the code you're currently using to try to override the selected dropdown view? It would also be great if you could share a mock of what you're trying to achieve.

from material-components-android.

EnriekNP avatar EnriekNP commented on June 8, 2024

ok , let me make it first

from material-components-android.

EnriekNP avatar EnriekNP commented on June 8, 2024

this is the code and the look that i want @afohrman ...
the dropdown layout

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    
    <com.google.android.material.textfield.TextInputLayout
        android:id="@+id/layoutDropDown"
        style="@style/Widget.Material3.TextInputLayout.FilledBox.ExposedDropdownMenu"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:hint="Test Exposed Drop Down"
        app:boxBackgroundColor="@null"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent">

        <com.google.android.material.textfield.MaterialAutoCompleteTextView
            android:id="@+id/autoComplelteTextView"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:drawablePadding="10dp"
            android:dropDownHeight="175dp"
            android:inputType="none"
            android:textColor="@color/black" />
    </com.google.android.material.textfield.TextInputLayout>

</androidx.constraintlayout.widget.ConstraintLayout>

the dropdown item layout

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/dropdown"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:gravity="center_vertical"
    android:orientation="horizontal">

    <ImageView
        android:id="@+id/dropdown_item_icon"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginVertical="10dp"
        android:paddingStart="24dp"
        android:paddingEnd="12dp"
        tools:src="@drawable/ic_test" />

    <TextView
        android:id="@+id/dropdown_item_name"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        tools:text="test" />
</LinearLayout>

the adapter

class TestAdapter(
    ctx: Context,
    resource: Int,
    private val items: List<Test>
) : ArrayAdapter<Test>(ctx, resource, items) {
    val inflater: LayoutInflater = LayoutInflater.from(ctx)

    override fun getItem(position: Int): Test {
        return items[position]
    }

    override fun getCount(): Int {
        return items.size
    }

    override fun getView(position: Int, convertView: View?, parent: ViewGroup): View {
        val view = convertView ?: inflater.inflate(
            R.layout.dropdown_item,
            parent,
            false
        )

        view.setPadding(0, view.paddingTop, view.paddingRight, view.paddingBottom)
        val item = items[position]
        val iconImageView = view.findViewById<ImageView>(R.id.dropdown_item_icon)
        iconImageView.setPadding(
            0,
            iconImageView.paddingTop,
            iconImageView.paddingRight,
            iconImageView.paddingBottom
        )
        val text1 = view.findViewById<TextView>(R.id.dropdown_item_name)
        iconImageView.setImageResource(item.icon)
        text1.text = item.name

        return view
    }

    override fun getDropDownView(position: Int, convertView: View?, parent: ViewGroup): View {
        return getView(position, convertView, parent)
    }

}

the class
data class Test(val icon: Int, val name: String)

and how i call the adapter in the fragment

        val listTest = getListItem()
        val testAdapter = TestAdapter(requireContext(), R.layout.dropdown_item,listTest)
        binding.autoComplelteTextView.setAdapter(testAdapter)

how it displaying
Screenshot_20240222-090455

what i want is like this (sorry if it's not good, i just edit the image in figma)
image

from material-components-android.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.