user7940066
user7940066

Reputation: 55

Android Textview marquee not working for first time

I have Textview it is intially hidden when activity loads.. When click on button it is shown.. But first time when textview is showing marquee doesnot work.. Unless it is working fine.. If screen get locked after unlocked it started working fine..

I am setting string as text in code and have also used setselected(true) in code..

<TextView
        android:id="@+id/txtInfo"
        android:layout_width="match_parent"
        android:layout_height="30dp"
        android:layout_below="@id/linearTtitle"
        android:background="@color/md_grey_300"
        android:ellipsize="marquee"
        android:freezesText="true"
        android:marqueeRepeatLimit="marquee_forever"
        android:scrollHorizontally="true"
        android:singleLine="true"
        android:text=""
        android:textColor="@color/md_black_1000"
        android:textSize="16sp" />` 

Upvotes: 1

Views: 1708

Answers (1)

Ankit
Ankit

Reputation: 1068

When you setSelected true to your textview at that time textview is not in a position to perform command so you can do it inside view.post so when it is active it will perform the operation.

Try this code inside your button

btn.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            tv.setVisibility(View.VISIBLE);
            tv.post(new Runnable() {
                @Override
                public void run() {
                    tv.setSelected(true);
                }
            });
        }
    });

Upvotes: 6

Related Questions