1

I have been reading up on simple_list_item_2 and other standardized ways of displaying multi line text on a listview but none have given me what I want. As of now I am using a custom layout for the listview, but I lack the knowledge (after reading multiple articles) on how to customize each row in the listview to display it's own line of large text, tooltip (small text), and picture.

Here is the code I am using to initalize the listview and set the adapter

//List View
        final String[] itemname = {
                "More Rockets",
                "Better Lasers",
                "Super Shield",
                "Super Defense"
        };

        final String[] itemtip = {
                "+1 attack",
                "+5 attack ",
                "+1 defense",
                "+5 defense"
        };

        final ListView upgradeList = (ListView) findViewById(R.id.upgradeListView);

        upgradeList.setAdapter(new ArrayAdapter<String>(
                this, R.layout.program_list,
                R.id.Itemname, itemname));

program_list.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent" android:layout_height="80dp"
    android:background="@drawable/buttontemplate">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textAppearance="?android:attr/textAppearanceLarge"
        android:text="Item Name"
        android:id="@+id/Itemname"
        android:textSize="30sp"
        android:layout_centerVertical="true"
        android:layout_toEndOf="@+id/imageView"
        android:layout_marginLeft="15sp" />

    <ImageView
        android:layout_width="30sp"
        android:layout_height="30sp"
        android:id="@+id/imageView"
        android:src="@drawable/heart"
        android:layout_marginLeft="20dp"
        android:layout_alignBottom="@+id/Itemname"
        android:layout_alignParentStart="true" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textAppearance="?android:attr/textAppearanceSmall"
        android:text="Tooltip:"
        android:id="@+id/toolTip"
        android:layout_centerVertical="true"
        android:layout_toEndOf="@+id/Itemname"
        android:layout_marginLeft="20dp" />


</RelativeLayout>

Here was my idea for puting another line of text in the listview but it is not the right amount of arguments

upgradeList.setAdapter(new ArrayAdapter<String>(
                this, R.layout.program_list,
                R.id.Itemname, itemname, R.id.toolTip, itemtip));

Any help is very much appreciated! -Kelton

Kelton_O
  • 148
  • 12
  • 1
    Why don't you use `BaseAdapter`? There you will have more control over adapter and layouts. I think that way you will get what you want – Marat Sep 07 '16 at 04:15
  • @Marat I didnt know that was a thing but i looked into it and it looks like exactly what i need. Thanks! – Kelton_O Sep 07 '16 at 04:18
  • Glad to know that. Your `CustomAdapterClass` should look something like this: http://stackoverflow.com/a/37783784/6272369 Then try to play around with TextView's xml attributes like `lines` or `maxLines` for better look. The material for it you can find here https://developer.android.com/reference/android/widget/TextView.html – Marat Sep 07 '16 at 04:33

1 Answers1

0

First make a POGO class with field String itemname,String itemtip then generate the getter and setter method , then from the activity class make an arraylist of this pogo class i.e

ArrayList<MyPOGO> arraylist =new ArrayList();
MyPOGO myPogo1=new MyPogo("More Rockets","+1 attack");
MyPOGO myPogo2=new MyPogo("Better Lasers","+5 attack ");
MyPOGO myPogo3=new MyPogo("Super Shield","+1 defense");
MyPOGO myPogo4=new MyPogo("Super Defense", "+5 defense");
arraylist.add(myPogo1);
arraylist.add(myPogo2);
arraylist.add(myPogo3);
arraylist.add(myPogo);

Here your arraylist size is 4 . Now make a baseadapter or recyler view pass this arraylist

Amit Ranjan
  • 547
  • 2
  • 11