Android的TextView中,在一个ListView选取框将无法运行动画它显示在拳头时间 [英] Android's TextView with marquee in a ListView won't animate for the fist time it is shown

查看:153
本文介绍了Android的TextView中,在一个ListView选取框将无法运行动画它显示在拳头时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个自定义适配器一个ListView。在它的每一个项目都包含一个TextView。

I've got a ListView with a custom adapter. Every item in it contains a TextView.

<TextView
    android:id="@+id/chat_name"
    android:layout_height="48dp"
    android:layout_width="match_parent"
    android:textColor="#FFFFFF"
    android:gravity="center_vertical"
    android:ellipsize="marquee"
    android:marqueeRepeatLimit="marquee_forever"
    android:singleLine="true"
    android:focusable="false"
    android:focusableInTouchMode="false"/>

我需要这个TextView中不成为焦点,因为我靠 onListItemClick()方法。当我了解, onListItemClick()如果你设置不会触发聚焦的=真正的

I need this TextView to not be focusable, because I rely on the onListItemClick() method. As I learned, onListItemClick() won't fire if you set focusable="true".

在我设置适配器:

TextView chatName = (TextView) v.findViewById(R.id.chat_name);
chatName.setText(chat.getChatName());
chatName.setSelected(true);

和它的作品每一次,但第一个。当一个项目被添加到该适配器它示出了在列表视图,但它不marqueed。当单击项目时,则显示另一个活动。用户返回到ListView之后,该项目突然marqueed。我想这marqueed所有的时间。

And it works every time but first one. When an item is added to the adapter it shows on the listview, but it isn't marqueed. When item is clicked, another activity is displayed. After the user returns to the ListView, the item is suddenly marqueed. I want it marqueed all the time.

我已经尝试与覆盖 isFocused()来始终返回true的方法继承TextView的,但是这并没有帮助。行为保持不变。我也尝试了不同值可聚焦 focusableInTouchMode 属性,但没有成功。

I have already tried subclassing the TextView with a method that overwrites isFocused() to always return true, but that didn't help. Behavior remained the same. I also experimented with various values of focusable and focusableInTouchMode attributes, but with no success.

推荐答案

请使用requestFocus()方法的功能如下。

Please use requestFocus() function as follows.

chatName.setSelected(true);
chatName.requestFocus();

我会工作。

这篇关于Android的TextView中,在一个ListView选取框将无法运行动画它显示在拳头时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆