I have simple ListView with ArrayAdapter which is working just fine. The problems start with RTL language (Arabic in this case).
When you open it for the first time, everything looks ok:
But after scrolling down and back up, some items appears to be rendered incorrectly:
The code is straightforward. Note that if I do not REUSE view and instead inflate it unconditionally every time (see the commented line below), the issue is GONE. But this is obviously not right, I want to REUSE items for better performance and smooth scrolling.
Please also note that I have multiple ListView
s in the app, and all of them shows this kind of incorrect rendering in Arabic. For this question I picked up the simplest case when I just set text and icon for every list item.
Please advice. The portion of code of my implementation of ArrayAdapter
:
public class PagesListAdapter extends ArrayAdapter<IPageRef> {
...
public View getView(int position, View convertView, @NonNull ViewGroup parent) {
final IPageRef b = getItem(position);
View row = convertView == null ? mInflater.inflate(R.layout.lang_item, parent, false) : convertView;
//View row = mInflater.inflate(R.layout.wordlist_item, parent, false);
TextView title = row.findViewById(R.id.title);
ImageView img = row.findViewById(R.id.img);
... // (setting the title & img properties)
return row;
}
}
lang_item.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="fill_parent"
android:gravity="center_vertical"
android:orientation="horizontal" >
<ImageView
android:id="@+id/img"
android:layout_marginBottom="5dp"
android:layout_marginRight="10dp"
android:layout_marginLeft="10dp"
android:layout_marginTop="5dp"
android:layout_width="50dp"
android:layout_height="38dp"
android:padding="1dp"
/>
<TextView
android:id="@+id/title"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center_vertical"
android:textSize="25sp" >
</TextView>
</LinearLayout>