Pressed Status propagation in Android - java

I have a layout with the following structure:
LinearLayout_1
ImageView
TextView
Linearlayout_2
ImageView
TextView
Some Views within LinearLayout_1 have padding and margins. I want to set a OnClickListener over LinearLayout_1 (for detecting clicks in the whole layout). But when its pressed I need all the items inside in pressed status. How can I do that? Thanks

Found a solution. The key is to use
android:duplicateParentState="true"
in the childs of the View where the clicks are listened

Related

how to make a checkbox editable when clicked in android studio

im trying to make a to do list in android studio with checkboxes, the idea is to be able to add checkboxes to a linear layout every time i press a button. this is pretty simple but i want to be able to change the checkbox text when i click on it after ive created it.
i tried to make the text box with no text and just place a plain text beside it but i havent found a way to place both of them on the same line of the linear layout. the plain text just appears on the line underneath. i would like to know if theres any way to make a custom component that would make the checkbox text editable when clicked on the text and check the box when clicked on the check box itself that i could place it in the linear layout.
this is the code ive done to add another checkbox to the linear layout:
public void click(View v)
{
LinearLayout.LayoutParams lparams = new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
CheckBox cb=new CheckBox(this);
cb.setLayoutParams(lparams);
cb.setText(t.getText());
this.ll.addView(cb);
}
Check the Checkbox what is it: Checkbox source
Now you know you have a "CompoundButton" , which is a Button if you look at the
source
which is a TextView if you check the source source
The EditText, which is used for editing texts it is a TextView if you check the source
So the parent it is a TextView and in your custom component you must combine the EditText added functions and values to your CheckBox. If you have time and you aren't lazy you can do it for sure, just extend the CheckBox and add the event and handling.
Solution ofered by BAHMAN is fast and simple ( but not enough elegant for me), if you want a quick result you can do that solution or based on that one:
Declare a View named "container" in .xml layout. At your code ( runtime ) first add the Checkbox. On the Click event remove the Checkbox ( if you arenn't added at .xml, but in code you can do it ) and add an Edit text, where you listen the finishing editting event. Then you remove the Edit text and put back the Checkbox. In this case you have not doubled the components and listeners.
Since it is a TODO list, can have many Checkboxes, I would choose the last solution offered by me. If you do an expensive, commercial product, than the first solution offered by me.
Instead of adding a check box to your layout you can add a horizontal linear layout or a custom view extending LinearLayout containing a CheckBox and an EditText at first set visibility of CheckBox to gone when user enters some text in EditText and presses Enter set CheckBox label equal to text of EditText then set visibility of EditText to gone and set Visibility of CheckBox to Visible. Again when a check box is clicked do similar job.
It is better for you to create a custom View (a class extending LinearLayout) and do above job in that class. and every time you need a new check box you can add this custom view to your layout instead of adding check box to your layout.

Controlling RecyclerView scroll from Seekbar

Is there any library or any way in which we can sync between the RecyclerView and the Seekbar.
By that I mean is that when I drag seekbar the items change, the seekbar width define the maximum scroll that the recycler can have. Similarly when I scroll the recyclerview the seekbar should update.
In short both should be in sync.
Or is there any other way to handle it.
What I am trying to achieve can be seen from the image attached to this question. Here top section is the seekbar and the bottom section is recyclerview.
Any solution or help is appreciated.
First of all, you can listen to the change of seek bar value by the setOnSeekBarChangeListener(). See get android seek bar value and display it on screen
.
Then, when seek bar value is changed, you can notify the recycler view to scroll to any position by the smoothScrollToPosition() of recycler view or smoothScrollToPosition() of linear layout manager

How can I expand a TextView programmatically in Android?

I have a TextView for description and I want it to display 4 lines by default, show the ellipsis and have a little expansion button. When the expansion button is pressed, the TextView should be expanded to display its entire contents, and the other elements on the layout should move down.
To show the ellipsis I am using desc.setEllipsize(TextUtils.TruncateAt.END); and I am setting the maxLines programmattically in the onClick event of the expansion/collapse button.
This works to expand the amount of text visible in the TextView, but it does not enlarge the TextView itself and push the rest of the layout down so you can see everything on the screen. How can I achieve this?
Simply using desc.setMaxLines(4); does not work to expand the TextView itself/increase its height. I have also tried using an ObjectAnimator to set the maxLines for the TextView but that has the same effect.
Thanks in advance for the help!
EDIT:
Code in onClick for animating the expansion:
ObjectAnimator animation = ObjectAnimator.ofInt(
desc,
"maxLines",
25);
animation.setDuration(400);
animation.start();
desc.setEllipsize(null);

Attach floating action button to element

I am trying to attach a floating action button (fab) to an element, as seen in this image.
I am using Shell Software's library (https://github.com/shell-software/fab). My XML consists of a RelativeLayout inside a Scrollview. Inside the relativelayout is an imageview and a textview. I want my fab to rest on the border of the imageview.
Thanks,
Geffen Avraham

Android Onclick priority: ListView or ImageView in ListView?

Theorical question
I have a listview populated with items, which layout is defined by one TextView and one ImageView.
I set an onclick listener on my listview for any item.
I set an onclick listener on my ImageView within my layout
Which one gets the priority when I click on my image and why?
How do I write code to manage this priorization?
Thanks!
You can add the attributes
android:focusableInTouchMode="true"
android:focusable="true"
for a layout that contains TextView and one ImageView.

Categories