RecyclerView jumps up when touching TextView that is selectable - java

I have a RecyclerView which is populated with items each containing a TextView. I call textView.setTextIsSelectable(true) on the TextView to make its text selectable, but I notice that when I tap on the TextView, or long press it to select text, the RecyclerView suddenly scrolls up so that the whole TextView is visible. I want to know how to disable this behaviour, so that touching or long pressing the TextView does not cause any scrolling.

Related

How to keep edittext focus when click other view or decide whether to change focus status before lose focus?

In my fragment, I have a layout contain several button, and this layout will change format when I focus and lose focus on editText.
here are images:
The problem is when editText is focused, I click those button or try to scroll the layout that contain buttons, editText lose focus directly, this make me can't scroll view also(because layout become not focus status).
And I don't want to use requestFocus at editTexts' onFocusChange, this will make other problem for me(like the soft keyboard will close and open again every time i click button, I want soft keyboard keep open and editText keep focus).
Is there any method to keep my editText focus? thanks.

Recycler view adapter remove items

I have two activities: HomePage and MyFavorites. Both have recycler views with items (similar to facebook posts) each item has a button, when you click on it, the item will be shown in the recycler view for MyFav activity. The code for when the button is clicked is in the Adapter class for the recycler view (both activities use the same adapter). Now when a user click on the button for the second time (while the user is in MyFav activity) it means that this specific item should be removed from the recycler view in MyFav activity, but when the button is clicked for a second time while the user is using/opening the HomePage activity the item shouldn’t be removed, the button will turn from red to white ONLY . How can i remove the item only from the recycler view in MyFav activity without removing it from the HomePage activity (since both use the same adapter for their recycler view) without making a new adapter?
If i create separate adapter class for each activity, is it good practice? Since the same code will be duplicated twice with minor changes.
Note: the button (Fav button) is a checkbox with a heart shaped icon, the color is initially white, it will turn red when clicked for the first time, and white when clicked again and so on..

ListView Scrolls to Top when EditText Grows

I have a Listview with EditTexts in every cell. Whenever I add text to the point that the EditText grows 1 line, the ListView scrolls to the top (and usually removes the EditText from view by doing so).
I found a few questions about this but they only seem to have "hacks" as answers and nothing that works for me.
ListView scrolls to top when typing in multi-line EditText
Listview with edittext - auto scroll on "next"
EDIT:
After a lot of research, I have found that it is because the editText is resizing, causing the ListView layout its subviews and then resetting to the top. I want to find a way for the EditText to grow while staying at the same place.
I tried this because of a suggestion I found online but, even though it keeps the ListView at the right height, it clears the focus from the EditText and I cannot seem to get it back with requestFocus.
private Stirng getTextWatcher(){
return new TextWatcher(){
#Override public void beforeTextChanged(CharSequence s, int start, int count, int after) {}
#Override public void onTextChanged(CharSequence s, int start, int before, int count) { }
#Override public void afterTextChanged(Editable s) {
listView.setSelection(index);
}
}
}
So what I would need is either:
Have a way for the ListView to not scroll automatically to the top when the subviews are being layed out again or
A way to focus my EditText after having called ListView.setSelected() or 3. Have another way to scroll the ListView that will not clear focus from the EditText.
For option
I have tried scrollTo() and smoothScrollToPosition(). scrollTo for some reason works but hides certain items from the ListView (they become invisible, not loaded). And smoothScrollToPosition() creates an animation where the ListView jumps to the top and then it brings the user back to the Item (and does it 2 or 3 times).
As par my view if you want to take input from ListView item by using EditText then you should use TextView in place EdiText and by click of TextView you should open and Input Dialog with EditText that is more simple and good solution. handling of EditText focus in ListView is vary difficult and you need to put extra Listeners for this.
OR
And if you have limited number of input box in your UI/UX then you can implement EditText with CustomListView by using ScrollViews.
ListView Scrolls to Top when EditText Grows
ListView has some known limitations related to child focus.
Solution
Why don't you try to use RecyclerView instead of ListView? Google introduced RecyclerView as the default recommended way of such UI. So custom ListView or hacks ore no more needed.
You can try adding this attribute to your ListView:
android:transcriptMode="normal"
This makes list automatically scroll to the bottom when a data set change notification is received and only if the last item is already visible on screen.
Read more here: attr_android:transcriptMode | Android Developers

ImageView Onclick Animation

Below is a picture of my app, I am currently using a modified version of this app to show my expandable content. Now my problem is with my ImageView, I currently have 3 layouts, one for the main dialog (with listview), one for the listview title & arrow and one for the item details (item row once expanded). I want to add animation to the ImageView so when you click the image or title textview, the list will expand and animate the change. How can I do this? I cannot get the onClick to work because it doesn't know there are 2 imageviews, it seens only one...
I will assume that your ImageView is this arrow inside your ListView element (because you didn't write it clearly enough).
You probably shouldnt try to attach onClickListener to your ImageView at all (nor to your ListView element title). The good way of implementing what you want you achieve would be to use ListView's onItemClickListener to detect clicks performed on specific items inside your listview, and then expanding appropriate expandable content.

Programmatically set TextView with Scrollbar on the top

I have a problem with TextView that has ScrollBar. I know that in order to create scrollbar on the textview, I need to enable this on the xml:
android:scrollbar="vertical"
and in the code.java, I set like this:
tvChapterDesc.setMovementMethod(new ScrollingMovementMethod())
Then, now user could scroll the TextView, if it is more than the defined number of lines. (say maxlines = 5).
However, I have a Button where if it is clicked, it is supposed to scrolled the textview to the top, can I do this? How? For example that the textview has 1000 lines, and there is a button "top". if user click button "top", it will be scrolled to the top immediately, so user can start reading to the beginning of the textview again. How to do that?
You should be able to use the scrollTo function on the textView.

Categories

Resources