Add subitem to my listview

0

I have a custom listview, with image and title, but I can not insert subtitle, see the codes:

Base adapter

public class AdapterListView extends BaseAdapter {

private LayoutInflater mInflater;
private ArrayList<Categoria> itens;

public AdapterListView(Context context, ArrayList<Categoria> itens) {
    //Itens que preencheram o listview
    this.itens = itens;
    //responsavel por pegar o Layout do item.
    mInflater = LayoutInflater.from(context);
}

/**
 * Retorna a quantidade de itens
 *
 * @return
 */
public int getCount() {
    return itens.size();
}

/**
 * Retorna o item de acordo com a posicao dele na tela.
 *
 * @param position
 * @return
 */
public Categoria getItem(int position) {
    return itens.get(position);
}

/**
 * Sem implementação
 *
 * @param position
 * @return
 */
public long getItemId(int position) {
    return position;
}

public View getView(int position, View view, ViewGroup parent) {
    //Pega o item de acordo com a posção.
    Categoria item = itens.get(position);
    //infla o layout para podermos preencher os dados
    view = mInflater.inflate(R.layout.item_list, null);

    //atravez do layout pego pelo LayoutInflater, pegamos cada id relacionado
    //ao item e definimos as informações.
    ((TextView) view.findViewById(R.id.text)).setText(item.getTexto());
    ((ImageView) view.findViewById(R.id.imagemview)).setImageResource(item.getIconeRid());

    return view;
}

}

XML:

<LinearLayout 
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="horizontal"
    android:padding="5sp">
    <ImageView
        android:id="@+id/imagemview"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        />

    <TextView
        android:id="@+id/text"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:textSize="20dp"
        android:layout_marginLeft="5sp"
        android:textStyle="bold"

        android:gravity="center_vertical"
        android:textColor="#FF000000"
    />


</LinearLayout>

How do I add a subitem, which is in the same template, but below the title and smaller?

    
asked by anonymous 25.11.2014 / 21:01

2 answers

1

Use a RelativeLayout, instead of using the LinearLayout. Try the following:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content">

<ImageView android:id="@+id/imagemview"
    android:paddingLeft="3dp"
    android:paddingRight="3dp"
    android:layout_width="48dp"
    android:layout_height="48dp"
    android:layout_gravity="center_vertical|center_horizontal"
    android:gravity="center" />

<LinearLayout android:id="@+id/textsContainer"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:orientation="vertical"
    android:layout_marginLeft="3dp"
    android:layout_toRightOf="@id/imagemview">

    <TextView android:id="@+id/text"
        android:layout_height="wrap_content"
        android:maxLines="1"
        android:ellipsize="end"
        android:layout_width="fill_parent"
        android:textIsSelectable="false"
        android:textSize="18sp"
        android:textStyle="bold"
        android:text="teste1"/>

    <TextView android:id="@+id/subtext"
        android:layout_height="wrap_content"
        android:maxLines="1"
        android:ellipsize="end"
        android:layout_width="fill_parent"
        android:textIsSelectable="false"
        android:textSize="14sp"
        android:text="dois"/>

</LinearLayout>

    
26.11.2014 / 00:41
0

You can create a map assigned to the text id. Example:

List[]
[PR("Paraná"),
SP("São Paulo"),
RJ("Rio de Janeiro"),
DF("Distrito Federal")
];

And the output:

List<Map<String, String>> =
    [ {text1="Paraná", text2="PR"},
      {text1="São Paulo", text2="SP"},
      {text1="Rio de Janeiro", text2="RJ"},
      {text1="Distrito Federal", text2="DF"},
];

The text will appear in subtitles.

    
26.11.2014 / 00:18