Hi,

I would like to create complex rows in a ListView (all of the rows
will have the same appearance, except the displayed text message of
course). Following is, from where I would like to start. I want each
row of the listview contain two lines. The second line will display
two text messages; the first one will be bold and the second one will
be italic.

Desired listview row:
  Text1
  Text21  Text22

I want Text21 to be bold and Text 22 to be italic.

Below I give the custom layout which I created and the code which
extends ArrayAdapter by implementing ComplexRowAdapter. The problem is
that the GUI appears distorted (I indicated in the code which lines
cause the distortion). Do you have any suggestions what might be going
wrong here?


The custome layout file (complex_row.xml)

<?xml version="1.0" encoding="utf-8"?>
<TwoLineListItem xmlns:android="http://schemas.android.com/apk/res/
android"
                 android:paddingTop="2dip"
                 android:paddingBottom="2dip"
                 android:layout_width="fill_parent"
                 android:layout_height="wrap_content"
                 android:minHeight="?android:attr/
listPreferredItemHeight"
                 android:mode="twoLine" >
    <TextView android:id="@+id/text1"
              android:layout_width="fill_parent"
              android:layout_height="wrap_content"
              android:layout_marginLeft="6dip"
              android:layout_marginTop="6dip"
              android:textAppearance="?android:attr/
textAppearanceLarge"
    />
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/
android"
                  android:layout_width="fill_parent"
                  android:layout_height="wrap_content"
                  android:layout_below="@id/text1"
                  android:layout_alignLeft="@id/text1"
                  android:orientation="horizontal" >
        <TextView android:id="@+id/text21"
                  android:layout_width="fill_parent"
                  android:layout_height="wrap_content"
                  android:textStyle="bold"
                  android:textAppearance="?android:attr/
textAppearanceSmall"
        />
        <TextView android:id="@+id/text22"
                  android:layout_width="fill_parent"
                  android:layout_height="wrap_content"
                  android:layout_toRightOf="@id/text21"
                  android:textStyle="italic"
                  android:textAppearance="?android:attr/
textAppearanceSmall"
        />
    </LinearLayout>
</TwoLineListItem>


The corresponding source code:

package com.example.complexrows;
import android.app.Activity;
import android.app.ListActivity;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

public class HelloAndroid extends ListActivity
{
  static final String[] ListViewItems = new String[] {  "Sometext1",
"Sometext2", "Sometext3", "Sometext4"  };

  @Override
  public void onCreate(Bundle savedInstanceState)
  {
    super.onCreate(savedInstanceState);
    setListAdapter(new ComplexRowAdapter(this));
    getListView().setTextFilterEnabled(true);
  }

  class ComplexRowAdapter extends ArrayAdapter
  {
    Activity context;

    ComplexRowAdapter(Activity context)
    {
      super(context, R.layout.complex_row, ListViewItems);
      this.context=context;
    }

    public View getView(int position, View convertView, ViewGroup
parent)
    {
      View row = convertView;

      if (null == row)
      {
        LayoutInflater inflater = context.getLayoutInflater();
        row = inflater.inflate(R.layout.complex_row, null);
      }

      TextView label=(TextView)row.findViewById(R.id.text1);
      label.setText(MenuItems[position]);

      label=(TextView)row.findViewById(R.id.text21);
      label.setText(MenuItems[position]);

      // !!!!!These lines distort the GUI!!!!!
      label=(TextView)row.findViewById(R.id.text22);
      label.setText(MenuItems[position]);

      return(row);
    }
  }

}

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to