Got a little problem with a functionality I'd like to implement.
I've got a LinearLayout, containing 2 TextViews. I'd want to set a onClickListener on it, so that it would behave just like an item in a ListView.
I've tried some possible implementation of this, and got it working using the xml attribute android:onClick of the LinearLayout.
As I want the application to visually react to a click on the LinearLayout (as in a ListView), I put this in the listener callback method :
l.setBackgroundColor(android.R.drawable.list_selector_background);
l is a LinearLayout object, initialised with findViewById();
I get an application not responding whenever I try to click on the layout. I tried to replace the code in the callback method by a Toast message show up, and it works, so I guess the problem is in the setBackgroundColor.
Is anyone familiar with this?
PS: sorry, I can't post more code right now, I'm at work.
You have to set LinearLayout attribute android:clickable="true" in the xml layout file or setClickable(true) in the java activity code.
i noticed that all the advices above don't helpt as long as any of the child elements inside the LinearLayout has the attribute android:textIsSelectable="true".
I found that that setClickable(true) would still cause clicks to go to children of the linearlayout. I found that to have the LinearLayout capture the touch instead of it's children I had to override the dispatchTouchEvent method so I created a subclass of LinearLayout for just this purpose. Seems like an ugly solution though.
you should set the LinearLayout's focusable to true and set all the children view's focusable to false, don't use the android:clickable="true", but you can't see the effect of the click of the linelayout. BTW, the best way is to implement the onTouchEvent api.
android:clickable="true" works perfectly under one condition.
Youhave to put the childs inside the LilnearLayout to android:clickable="false".
Had the same problem, I've been trying for an hour all the answers in SO but none worked.
Then I realized I just had to promote my LinearLayout to the bottom of the layout, since other views blocked it, and then it worked, without adding ANY special attributes to the layout.
Putting it here in case it might help someone someday.
Related
I need some help, i want the android scrollview animation effect....
Basically when the someone click on the textview of linearlayout in scrollview another horizontal view should come in.
Here is the pic....
What you could do is setup ontouch() on the textview. once you touch it then you would make the layout visible with setVisiblity(). you could even add in a animation to make it more professional.
You would probably get a bug if you didnt make every other view GONE, when you touch a new textview.
I like this idea and I might work around with it myself!
Good Luck
I'm going completely mad.
I'm attempting to create a RadioGroup that extends RelativeLayout instead of LinearLayout. Seems easy enough. I'm following [this] exactly. Everything's double and triple checked. This seems to have worked for a bunch of other people just fine.
Upon actually using it, the RelativeLayout attributes specified by the children are completely ignored. Everything piles up in the top left and nothing I can do will move them.
If I change the view from RadioGroupRelative to a regular RelativeLayout, everything is suddenly following the 'android:layout_' attributes perfectly. Looks exactly the way I want it to look.
So. Somewhere along the lines, and I've redone this like 5 times now, I'm losing those xml attributes. I don't understand how though. RadioGroup doesn't do anything to it's children's layout parameters from what I can tell. Why aren't they getting applied when android inflates the layout?
There is no link for [this] - could you add it? Also, mind posting your source code for your custom RadioGroup that inherits from RelativeLayout. From what i can tell, RadioGroup is-a LinearLayout so I'm assuming you've copied and customized the Android source code to do this...
EDIT: as a test, what does the following code do in your environment?
YourCustomRadioGroup radioGroup = new YourCustomRadioGroup(this);
if (radioGroup instanceof RelativeLayout){
//do you end up in here?
Log.d("yourapp","I'm a RelativeLayout!!");
}else{
Log.d("yourapp","I'm NOT a RelativeLayout! :( ");
}
i'm facing a problem that i never came accross before:
well i successfully applyed the 3D transition between a listview and someother layout container some info about the selected item. well the probelm is: some of the textviews are displayed correctly while others display nothing, even the imageview is shown as expected...
any suggestions?
thanks in advance..
I guess you had same collision in android:name tags. Acting wierd could happen by many reasons, but one of the most liklly to happen is when you have some collision in names, I mean more views defined with same name
#+id/something definition and #id/something reference is okey
but having #+id/something twice sometimes could be a problem.
This kind of references is usually used in relative layaout when you say I want this view to be to the left (or above, or below) some other view. Then you must give a reference to other view...
I fixed this: well i don't know the exact reason but it solved the problem
i changed the textview id in the layout and it worked fine. Weird why it didn't work until this..if any one can explain it would be great^^
I have 2 text view with the same id, one of them is inside the parent layout and the other one was in the viewpager which is child of the parent layout. I changed the latter one is and the problem is solved.
I'm developing a list view in which each cell is a LinearLayout with other views inside it. I have also set the onClickListener of the cells to take the user to another Activity.
The problem is that one of the views inside is a TextView in which I apply the Linkify function. When the TextView happens to have a link in its text, I cannot trigger the onClickListener anymore, unless I click on another view of the LinearLayout. This problem also applies to the highlighting feature.
Does anyone knows what may be happening?
Thanks!
If you are applying the Linkify function inside of your getView() Override, I would wonder if it's just automatically setting the "Clickable" type methods on the view being passed to it. Right after Linkify, you could try calling setClickable(false), setFocusable(false), setFocusableInTouchMode(false) all on the view that was Linkified.
I have a set of images inside horizontal scrollview. I want to perform click event on these images. I have added onClickListener to the images. But its not working. I think since images are inside scrollview the problem arises. Can anyone help on this issue?
I used OnTouchListner instead of OnClickListener and applied it to the images inside ScrollView. Now I am able to do it.
#Desiderio : I used ScrollView for some other purpose. I required it for my appn. It doesnt interfere with my pbm. Sorry, I made mistake while explaining my pbm.