inputType makes item un-clickable
I have a ListView
in which each item has a complex layout that contains, at some point, a TextView
with android:inputType="text"
and android:ellipsize="marquee"
. My problem is that inputType="text"
does something that renders the whole listview item un-clickable. I've tried:
android:descendantFocusability="blocksDescendants"
on the top-most layout of an item,android:focusable="false"
on theTextView
itself,android:focusableInTouchMode="false"
on theTextView
itself,android:clickable="false"
on theTextView
itself,android:editable="false"
on theTextView
itself.
Nothing worked.
The reason why I use android:inputType="text"
on a TextView
is so that it becomes single-line and android:ellipsize="marquee"
actually works. I've done my homework:
android:singleLine
is deprecated*android:lines="1"
, as suggested here, doesn't work, the text still wraps, you just don't get to see the second line, so the marquee effect does not appear.
* or is it? My Ctrl+Space in Eclipse says this about android:singleLine
(emphasis mine):
Constrains the text to a single horizontally scrolling line instead of letting it wrap onto multiple lines, and advances focus instead of inserting a newline when you press the enter key. * Deprecated: This attribute is deprecated and is replaced by the textMultiLine flag in the inputType attribute. Use caution when altering existing layouts, as the default value of singeLine is false (multi- line mode), but if you specify any value f开发者_运维知识库or inputType, the default is single-line mode. (If both singleLine and inputType attributes are found, the inputType flags will override the value of singleLine.). [boolean]
However, the docs do not say anything about any deprecation.
What's going on here?
Actually in the official documentation of R.attr that attribute constant is deprecated.
However (as mentioned) this is contradicting the TextView documentation page. And when looking at the related methods, setting the singleLine attribute is equivalent to :
myTextView.setTransformationMethod(new SingleLineTransformationMethod());
which too isn't deprecated. And it is how i dance around that deprecation.
Not sure if I fully understand your needs, however if I do here is the code I used for list item (it has image on the left and text on the right, the text is limited with 2 lines and uses ellipsize feature):
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="?android:attr/listPreferredItemHeight"
android:orientation="horizontal"
android:gravity="center_vertical"
android:padding="5dip">
<ImageView android:id="@+id/list_item_icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingRight="10px" />
<TextView android:id="@+id/list_item_label"
android:textSize="16sp"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:ellipsize="marquee"
android:maxLines="2"
android:inputType="textMultiLine" />
</LinearLayout>
If you need 1 line limit probably try to use android:maxLines="1"
?
As long as the official, online documentation does not mention that singleLine
is deprecated, I will not consider it so. It must be a bug in the SDK. I will use singleLine
for as long as it is not marked as deprecated in the documentation and until there's a fully working, non-deprecated alternative.
精彩评论