I am using recyclerview where item can have multiline text.the problem arise when one item has single line text and other has multiple lines of text.one item get bigger than other.
I want item height will be same as talles item.How i can achive this?
You can give fixed height to TextView. Like
android:layout_height="50dp"
Or you can set fix number of lines of TextView
android:lines="2"
This will help you inside your Textview tag in the listItem
android:maxLines="1"
android:marqueeRepeatLimit="4"
This will help text to scroll if its long engouh for one line
I want to add custom grid divider to RecyclerView , I have no idea please suggest some idea. For first row divider should start from beginning and for others it should be centered.
For your solution we need to access middle column sequence 1,4,7,10... to get that
if (i % 3 == 1) {
System.out.print(i);
}
from this you'll get position and by that change/ add padding to line
I have a dialog containing a list of notes, and I want to make the user scroll to the end of the list to find the "OK" button to close the dialog.
The dialog contains a ListView and I add the button to the list using the footer row.
View footerView = ((LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE)).
inflate(R.layout.list_footer_button, null, false);
listView.addFooterView(footerView);
When i turn on talk back and open this dialog, it reads the wrong count for the ListView as it is including the footer row. For example if my list has 3 items, talkback reads "Item 1 of 4".
ISSUE
How can i get talkBack to read the correct number of items ignoring the footer row?
OR
If i can't change this, how else do i create a dialog where the user has to scroll to the end of the list before seeing the button to dismiss the dialog.
I have resolved this issue by adding the button to the View for the last row rather than adding a footer.
My layout for each row contains a textView and a button, and the button is set to be "invisible".
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<LinearLayout android:id="#+id/notes_details"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<!-- other views here but removed for this post -->
<TextView
android:id="#+id/notes_text"
style="#style/notes_text_style"/>
</LinearLayout>
<Button
android:id="#+id/notes_button"
style="#style/notes_button"
android:layout_below="#id/notes_details"
android:layout_centerHorizontal="true"
android:visibility="invisible" />
</RelativeLayout>
In the adapter for the list, I show/hide the button based on whether the row is the last row
boolean isLastRow = iPosition == getCount()-1;
okButton.setVisibility(isLastRow ? View.VISIBLE : View.GONE);
Accessibility changes needed
There was additional work to make this all work for Accessibility purposes. If no changes were made to support accessibility, only the rows are navigatable. Therefore the last row will select the notes text and OK button as one selectable item and you would not be able to navigate to the button using a keyboard/trackerball.
Firstly you have to set the list so that items in a row are focusable
listView.setItemsCanFocus(true);
Secondly, in code in the adapter, i set the focusable/nextFocusXXX on the notes textView and button accordingly
// when in accessibility mode, we want to set the navigation order for
// the list item's text and the OK button
boolean isLastRow = iPosition == getCount()-1;
if (isAccessibilityEnabled) {
notesTextView.setFocusable(true);
okButton.setFocusable(true);
rowView.setNextFocusForwardId(isLastRow ? R.id.notes_button: R.id.notes_text);
rowView.setNextFocusDownId(isLastRow ? R.id.notes_button: R.id.notes_text);
okButton.setNextFocusUpId(R.id.notes_text);
}
I had another usecase with this issue.
Requirements
I have a screen containing a list of items and I have a Floating Action Button (FAB) on the bottom right of the screen allowing the user to add items to the list. On the right hand side of each row is a button presenting options for that row item.
I need the FAB to not overlay the last row in the list, otherwise I am never able to click on the right hand button of the last row as it will be under the FAB.
Solutions and their issues
I tried several solutions. One was adding an extra count to the list items and when getting the view for this last row I return an empty view, the height of the FAB. I also tried adding this empty padding row as the list footer. In both cases TalkBack reads one too many for the number of items in the list.
I can not use the solution I have posted for this question for my list of notes. I need the FAB to always be in the bottom right hand side of the screen (not just after the last row) even if there are only 1 or 2 items in the list or over a screen-full of items.
Working Solution
Adding the last 4 attributes in the code below to my list definition in the xml layout seems to solve the issue. There are no additional items added to the list so TalkBack reads the list count correctly and the following ensures the FAB in the bottom left of the screen never overlaps the last row.
<!-- Instead of adding a footer row to stay clear of the FAB,
add a padding to the listView and set clipToPadding to false
android:overScrollFooter is set to transparent to avoid having a divider
for the last item so there is just white space below the last item -->
<ListView
style="#style/my_list_style"
android:layout_alignParentTop="true"
android:paddingBottom="82dp"
android:clipToPadding="false"
android:footerDividersEnabled="false"
android:overScrollFooter="#android:color/transparent"/>
I'd like to add a dummy item (or 2) at the end of a ListView to make the final item easier to access. Padding the ListView will limit the entire ListView which is not what I am looking for. Is there a way to add one which is not clickable and is only there to lift up the final item?
I know exactly what you want.
Do this in your layout:
<ListView
...
android:paddingBottom="16dp"
android:clipToPadding="false" />
clipToPadding when set to false will add that space in the end of your ListView if you have added padding. Its default value is set to true and that causes the padding to stay annoyingly always at the bottom of the view. You know what I mean.
I've created an android application with a ListView. I've added both a header and footer to the list. But when adding a divider/separator it also creates an empty space between the header and the first ListView item. It does the same for the last ListView item and the footer.
The empty space is equivalent to the size of the divider between all the ListView items, with the difference that it doesn't draw the divider and just leaves empty space. I thought I found the solution with the xml attributes 'Footer dividers enabled' and 'Header dividers enabled'. But when setting them to false, it doesn't change anything. I even tried to set them programmatically with
list.setFooterDividerEnabled(false);
list.setHeaderDividerEnabled(false);
But it just doesn't work. Any way to fix that problem? I just don't want the empty space to be there, I want the first item to fit exactly to the header (same for the footer).
I stumbled upon the same problem, but in a slightly different situation than yours. My ListView has a header (a search box), but the first item below it contains a section header (a date, or a letter) rather than being a regular list item (with the actual content in form of an image, some text, and so on). As such, I want it not to be selectable, so in my custom adapter I have overridden areAllItemsEnabled to return false.
Big mistake, because that's exactly the culprit. See, it appears that, by design, the ListView implementation only draw dividers between two enabled items, but still reserve space for dividers between an enabled item and a disabled one even if those dividers will not be drawn. The fact this is a conscious design decision does not mean it's not stupid, of course. Most weird of all, this dividers drawing policy is based just on the value returned by areAllItemsEnabled instead of the values returned by single calls to isEnabled for subsequent items.
Thus, to work around it, I just had to return true from areAllItemsEnabled (I kept the overridden method and add a comment about this issue, otherwise I would not be able to remember it a month from now): lo and behold, white space disappeared, replaced by a divider. Now, if I want to show the ListView header and the first section header as being exactly adjacent, I just have to choose a divider color that's the same as the section header color.
Really hope that's the same case as yours, or that my solution helps you in some other way.
I tried a solution by 幻影浪子 that works (based on android-pulltorefresh):
View Layout (header.xml):
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<RelativeLayout
android:id="#+id/content"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<ProgressBar
style="#android:style/Widget.ProgressBar.Small.Inverse"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_margin="16dp"
android:layout_marginTop="2dp" />
</RelativeLayout>
</LinearLayout>
Inflating View:
m_headerView = inflater.inflate(R.layout.header, this, false);
Displaying View:
m_headerView.setPadding(0, 0, 0, 0);
m_headerView.setVisibility(View.VISIBLE);
Hiding View:
m_headerView.setPadding(0, -1000, 0, 0);
m_headerView.setVisibility(View.GONE);
It worked perfectly in our project. I hope it is helpful.
In getview method you can check if the item is first or last and set custom devider which will be of 0 height or single pixel height of transparent color.
goto the ListView properties in android layout and search for spacing tag... some how in android, when creating new layouts, it will defaults creation is spacing header spacing and border properties. check it , if it is available then remove it
Didn't find a great solution.
Set dividerHeight="0dp" and created my own dividers manually - either directly in the layout XML or dynamically in the adapter if you need more precise control.
Just do
list.setDividerHeight(0)
That should take care of it.