1

I using https://github.com/hakobast/DropdownTextView in version 0.1.1 version 0.3.1 is not suitable for me. I'm wondering if it any chance to change the frame colour when I click DropdownTextView. The second thing is how can I move the DropdownTextView title to the centre? As you can see I have all gravity in centre mode and nothing happens.

My code:

MainActivity.kt

package com.example.myapplication

import android.content.Context
import android.os.Build
import android.os.Bundle
import android.view.*
import android.widget.*
import androidx.annotation.RequiresApi
import androidx.appcompat.app.AppCompatActivity
import com.google.gson.Gson
import hakobastvatsatryan.DropdownTextView


class MainActivity : AppCompatActivity()
{
    @RequiresApi(Build.VERSION_CODES.O)
    override fun onCreate(savedInstanceState: Bundle?)
    {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)

        var zwrotkaString = """{

}"""
        var stat:Statistic = Gson().fromJson(zwrotkaString, Statistic::class.java)

        val d = findViewById<ListView>(R.id.first_dropdown_text_view_list)

        d.adapter = MyCustomAdapter(this@MainActivity, stat);
    }

    private class MyCustomAdapter(context: Context, stat: Statistic): BaseAdapter()
    {
        val statS:Statistic

        private val mContext: Context
        init
        {
            mContext = context
        }

        init
        {
            statS = stat
        }

        override fun getCount(): Int {
            return statS.statisticsForGroups.size;
        }

        override fun getItem(position: Int): Any
        {
            return statS.statisticsForGroups[position];
        }

        override fun getItemId(position: Int): Long
        {
            return position.toLong();
        }

        override fun getView(position: Int, convertView: View?, parent: ViewGroup?): View
        {
            val layoutInflater = LayoutInflater.from(mContext);
            val rowMain = layoutInflater.inflate(R.layout.rowlistviewstatistic, parent, false)
            val statDropDownText = rowMain.findViewById<DropdownTextView>(R.id.dropdowntextrow)
            
                statDropDownText.setTitleText("Title")
                statDropDownText.setContentText("Content")

                return rowMain

        }
    }
}

activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    tools:context=".MainActivity"
    tools:openDrawer="start"
    android:layout_gravity="center"
    android:gravity="center"
    >


    <ListView
        android:id="@+id/first_dropdown_text_view_list"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:divider="@android:color/transparent"
        android:dividerHeight="20sp"
        android:scrollbarStyle="insideInset"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.0"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/textViewMain"
        app:layout_constraintVertical_bias="0.403"
        tools:ignore="MissingConstraints"
        android:layout_gravity="center"

        />


</LinearLayout>

rowlistviewstatistic.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:gravity="center"
    android:layout_gravity="center"
    android:orientation="vertical"
    >

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:text="qweqdasdasdasdadaq aa fadfeaeef"
        />

    <hakobastvatsatryan.DropdownTextView
        android:id="@+id/dropdowntextrow"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        app:content_text_color="@color/purple_500"
        app:arrow_drawable="@drawable/ic_arrow"
        app:title_text_color="@color/colorRed"
        android:layout_gravity="center"
        android:gravity="center"
        app:title_text_size="30sp"
        app:bg_drawable_expanded="@drawable/answer_drawable"
        android:clickable="true"
        android:focusable="true"
        />

</LinearLayout>

answer_drawable.xml

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">
    <stroke
        android:width="1dp"
        android:color="@color/answer_border" />
    <corners android:radius="5dp" />
</shape>
mad_lad
  • 654
  • 3
  • 8
  • 20
BinaryMan
  • 55
  • 6

2 Answers2

1

I fixed the 0.3.1 crash and released 0.3.3 please try and let me know if it fixes your problem. I am not the owner of the library I forked it and fixed the crash and have to release it on jitpack rather than bintray(jcentre) as it deprecated.

Please find the detail for integrating the library at

https://stackoverflow.com/a/67520594/4828650

Dinkar Kumar
  • 2,175
  • 2
  • 12
  • 22
0

I'am wondering if it any chance to change frame color when I click DropdownTextView

Add OnClickListener to your TextView and once the user clicks it change the frame color

statDropDownText.setOnClickListener(new OnClickListener() {
    @Override
    public void onClick(View v) {
     statDropDownText.setRegularBackgroundDrawableRes(R.drawable.answer_drawable)

    }
});

Second thing is how can I move DropdownTextView title to center ?

After going through the source code I found this method getTitleTextView(). Calling this will return the TextView, and set gravity to center.

TextView ta = (TextView) getTitleTextView();
LayoutParams lp = new LayoutParams();
lp.gravity = Gravity.CENTER_HORIZONTAL;
ta.setLayoutParams(lp);
mad_lad
  • 654
  • 3
  • 8
  • 20
  • Thanks for the answer, but I do not have those options in 0.1.1 version – BinaryMan May 07 '21 at 17:19
  • @BinaryMan "but I do not have those options in 0.1.1 version" you mean both of them – mad_lad May 07 '21 at 17:53
  • statDropDownText.setBackgroundResource() This is available in kotlin in both version 0.1.1 version 0.3.1 do not work properly for me – BinaryMan May 07 '21 at 20:45
  • Is getTitleTextView() working for you. Why don't you call it, and use https://stackoverflow.com/a/6932112/9846650 on the textview instead of statDropDownText.setBackgroundResource() – mad_lad May 08 '21 at 05:34
  • I chect it and let you to know – BinaryMan May 08 '21 at 17:13
  • I face that problem https://stackoverflow.com/questions/61731493/aapt-error-resource-attr-title-text-aka-com-example-dropdowntextviewattr-tit When I update dropdown... to 0.3.1 version Options above are avaiable only 0.3.1 version – BinaryMan May 09 '21 at 10:46
  • @BinaryMan i think its better to make a github issue – mad_lad May 09 '21 at 14:34
  • it is. https://github.com/hakobast/DropdownTextView/issues/14 – BinaryMan May 09 '21 at 15:00