java - Clickable layout with inner views behavior issue -


I am testing to create a compound view, so I started with a linear layout that has an image view and a textView . This linerlayout will represent a scene similar to the partial list, and I made it clickable. The internal view of the layout is the color (textview) and image (image view) of the selectors. In API 19 (KitKat), click behavior is fine (screenshot 1) but on API 15 and API 10 (screenshot 2), the click did not change the selector state.

Each code is Android: Android: layout_height = "wrap_content" android: background = "@ drawable / listitem_login" Android: clickable = "true": "list item" is:

  Android: line_liveout Android: Android: gravity = "center" Android: orientation = "horizontal" Android: padding = "15dp" & gt; & Lt; ImageView android: layout_width = "wrap_content" Android: layout_height = "wrap_content" Android: layout_marginRight = "10dp" Android: src = "@drawable / signin_signies_ICN_facebook" / & gt; & Lt; Android: attribute / textAppearanceMedium "Android: layout_width =" wrap_content "Android: layout_height =" wrap_content "Android: text =" Facebook "Android: textColor =" @ color / option_text_color "/> & Lt; / LinearLayout & gt;  

API19

Edit: I used the touch listener approach if I was getting the best solution someday (without Java code), I edit here. Based on the answer, my viewpoint, (a scene for liner layout. Adding an on-the-link):

  @override public boolean on-touch (view view, motion event motion event) {view group Container = ViewGroup; Boolean pressed; If (motionEvent.getAction () == MotionEvent.ACTION_DOWN) pressed = true; Else if (motionEvent.getAction () == MotionEvent.ACTION_UP) pressed = false; Second false return; For (Int i = 0; I & lt; Container.GetBillCount (); I ++) {Container.Get ChildAtt (I) .Pressed Press; }      return false; }  

The code runs a bit slow in Android 2.3 but it also works.

I tried in various APIs and have the same problem with you. I think the old API can not have this feature which allows the appearance of the internal view to respond to its parental click method.

You can change the look of the internal view in your code using touch codes or you use LinearLayout but use only one TextView, android: drawableLeft with a picture in it, Then you can change both image and text and background at the same time.

Edit: Using onTouchListener:

  @ Override Public Boolean On Touch (see V, Motion Event Event) {if (event.getAction () == MotionEvent.ACTION_DOWN} {imageView.setPressed (true); textView.setPressed (correct);} and if (event.getAction () == MotionEvent.ACTION_UP} {imageView.setPressed (wrong); textView.setPressed (wrong);} Description is false;}  

Hope this helps you.


Comments

Popular posts from this blog

import - Python ImportError: No module named wmi -

Editing Python Class in Shell and SQLAlchemy -

lua - HowTo create a fuel bar -