0

I am using Arrayadapter with android.R.layout.simple_list_item_1 child here is the getView function

@NonNull
@Override
public View getView(int position, View convertView, ViewGroup parent) {

    if (convertView == null)
        convertView = this.inflater.inflate(res, parent, false);

    TextView textView = (TextView) convertView.findViewById(android.R.id.text1);
    textView.setTextColor(ContextCompat.getColor(ctx, R.color.white_overlay));
    textView.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
    //textView.setLayoutDirection(View.LAYOUT_DIRECTION_RTL);

    textView.setText(filterData.get(position).getTitle());
    textView.setGravity(Gravity.CENTER_VERTICAL | Gravity.START);

    return convertView;

}

and iam applying filter on the list data here is the filter code private class MyFilter extends Filter {

    @Override
    protected FilterResults performFiltering(CharSequence charSequence) {
        String filterStr = charSequence.toString().toLowerCase();
        FilterResults results = new FilterResults();

        int count = data.size();
        List<Extras.Area> tempRes = new ArrayList<>(count);

        for (Extras.Area area : data) {
            if (area.getArTitle().toLowerCase().contains(filterStr)
                    || area.getEnTitle().toLowerCase().contains(filterStr))
                tempRes.add(area);
        }

        results.values = tempRes;
        results.count = tempRes.size();

        return results;
    }

    @SuppressWarnings("unchecked")
    @Override
    protected void publishResults(CharSequence charSequence, FilterResults filterResults) {
        filterData = (List<Extras.Area>) filterResults.values;
        notifyDataSetChanged();

    }
}

my problem is the text gravity for each item is always left even when the local direction is RTL here is an example enter image description here

i have try to use custom layout but this didn't solve the problem for me .

Raafat Alhmidi
  • 880
  • 9
  • 17
  • It's easier to set the gravity of the parent view, not the textview. If you set the gravity of the textview, the textview needs to be match_parent in order for the text to appear on the right of the parent view. – Christine Nov 11 '16 at 23:32

1 Answers1

-1

You should show us the XML file, but i imagine that your attribute layout_width from your TextView is match_parent. You should put layout_width to wrap_content and the attribute layout_gravity center. Hope that helps!

  • actually i don't have XML file .. i was creating this dialog layout pragmatically , now i create it in XML file and that's solved my problem :) – Raafat Alhmidi Nov 17 '16 at 08:37