Workaround to android:singleLine for items in a ListView without sacrificing itemClickListening functionality
Due to this feature in Lis开发者_Go百科tViews, items cannot gain focus if you want ListView to be able to listen to click events through onItemClick or onListItemClick. Now this is a problem if you want a TextView in an item to be single-lined at the same time. Because if you set android:inputType="text"
, the TextView somehow becomes "clickable", thus gaining focus.
I'm currently using android:singleLine="true"
as a workaround, but it is listed as depreciated. Are there any "legit" or non-depreciating methods in doing this.
Try..........
android:maxLines
inputType
really makes more sense for EditText
. If you really want to use it, can't you just set android:clickable="false"
and android:focusable="false"
?
Also, look into android:ellipsize
if you don't like the first solution.
精彩评论