0

I have a ListView with 2 options. I have implemented this in a helper class with this code:

public void DrawAreas() {
    ListView areaView = (ListView) _activity.findViewById(R.id.area_list);

    ArrayAdapter<TdcArea> areas = new ArrayAdapter<TdcArea>(_activity.getApplicationContext(),
            android.R.layout.simple_list_item_1,
            _system.getAreas()) {
        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            View view = super.getView(position, convertView, parent);
            TextView text = (TextView) view.findViewById(android.R.id.text1);
            text.setTextColor(Color.BLACK);
            return view;
        }
    };
    areaView.setAdapter(areas);
    //areaView.setOnItemClickListener()
}

That works, however, I want to place a ">" aligned to the right of each item, showing that the item is clickable and after clicked, another page will be shown.

How to draw that ">" to the right?

Regards Jaime

jstuardo
  • 2,687
  • 10
  • 44
  • 101
  • You mean set the text with a ">" in it? I don't see where you're setting anything other than the color. – durbnpoisn Oct 15 '15 at 16:02
  • _system.getAreas() retrieves an array of objects. Each object override the toString method, so that, ListView actually writes a property called "Name". If I add the ">" to the text,, that sign will appear not aligned to the right, since all texts have different lengths. – jstuardo Oct 15 '15 at 16:07
  • 1
    please post your xml file. In which you can use a `ImageView` with `alignParent_toRight="true"` and having `src` of an arrow from drawable. – Vipul Asri Oct 15 '15 at 16:11
  • The XML file is not controlled by me.. it is retrieved from an external WebService and created a object model from it in my application. – jstuardo Oct 15 '15 at 16:24
  • Please note that what you are trying to do is strictly against design guidelines for Android, as noted in the Developer Site [here](http://developer.android.com/design/patterns/pure-android.html). Either scroll about half way down the page or search for "Don't use right-pointing carets on line items". Apologies for a no answer but I just wanted to make you aware of the recommended guideline. – lustig Oct 15 '15 at 16:30

2 Answers2

4

Just add a "chevron right" drawable to your project and then set it to your TextView:

// getting drawable as chevron_right
text.setCompoundDrawables(null, null, chevron_right, null);
Vitaly Zinchenko
  • 4,547
  • 4
  • 32
  • 49
  • Can you give me more details please? should I create an icon and place it in res folder? – jstuardo Oct 15 '15 at 16:26
  • you can download it from here http://uxrepo.com/icon/android-chevron-right-by-google-material (png) and copy it to your "drawable" folder – Vitaly Zinchenko Oct 15 '15 at 16:34
  • sorry but I cannot make that method to work. I am calling it from a helper class, but I pass the activity in constructor. I am stuck trying to get Drawable object. I tried _activity.getResources().getDrawable(R.drawable.chevrom_red) but android studio says it is deprecated. I tried _activity.getDrawable(R.drawable_chebvron_red) and an error ocurs telling that call requires API level 21. Please help. – jstuardo Oct 15 '15 at 19:14
  • Thanks! but I needed to use setCoumpoundDrawableWithIntrinsicBounds – jstuardo Oct 15 '15 at 21:45
0

The CHEVRON RIGHT icon is part of Clip Art Asset Type offered in Android Studio´s icon gallery. Here goes the steps:

1 - On Android Studio, right click on "res" folder and select New/Vector Asset
2 - Asset Type: Clip Art
3 - Click on "Clip Art" and find "chevron right"
4 - Color #CCCCCC
5 - Click "next" and then "finish"
6 - Now you can use it in your cell adapter like this:

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="40dp"
    android:background="@color/white"
    android:gravity="start|center_vertical"
    android:orientation="horizontal" >


    <TextView
        android:id="@+id/history_details_list_item"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:layout_marginStart="15dp"
        android:layout_marginEnd="15dp"
        android:maxLines="1"
        android:ellipsize="end"
        android:textColor="#000000"
        android:textSize="11sp" />


    <android.support.v7.widget.AppCompatImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginRight="15dp"
        android:layout_marginEnd="15dp"
        app:srcCompat="@drawable/ic_chevron_right_black_24dp"/>


</LinearLayout>
Roney Sampaio
  • 231
  • 3
  • 6