1. Download our Official Android App: Forums for Android!

Custom ListAdaptor Issues

Discussion in 'Android Apps & Games' started by mm2345, Feb 22, 2011.

  1. mm2345

    mm2345 Lurker
    Thread Starter
    Rank:
    None
    Points:
    5
    Posts:
    1
    Joined:
    Feb 22, 2011

    Feb 22, 2011
    1
    0
    5
    Hey everyone, I'm a little stuck right now. i'm getting some funky errors when I try run my project.

    Basically what it's doing is pulling a number of entries from a DB and displaying them in a custom ListAdaptor.

    I'm getting "ArrayAdapter requires the resource ID to be a TextView" as a error

    Here's where the Listview is populated

    ______________________________
    public View getView(int position, View convertView, ViewGroup parent) {

    View v = convertView;
    if (v == null) {
    LayoutInflater vi = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    v = vi.inflate(R.layout.status_container_list_entry, null);
    }
    JobListAdaptor o = items.get(position);
    if (o != null) {
    TextView tt = (TextView) v.findViewById(R.id.toptext);
    TextView mt = (TextView) v.findViewById(R.id.middletext);
    TextView bt = (TextView) v.findViewById(R.id.bottomtext);
    //TextView st = (TextView) v.findViewById(R.id.sidetext);

    if (tt != null) {
    tt.setText("Name: "+ o.getName());
    }
    if(mt != null){
    mt.setText("Provider: "+ o.getProvider());
    }
    if(bt != null){
    bt.setText("Most Recent Feed Date: "+ o.getMostRecentFeedDate());
    }
    //if(st != null){
    // st.setText("Status: "+ o.getStatus());
    //}

    }
    return v;
    ______________________________


    Here's the XML display

    ______________________________
    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="?android:attr/listPreferredItemHeight"
    android:padding="6dip">
    <ImageView
    android:id="@+id/icon"
    android:layout_width="wrap_content"
    android:layout_height="fill_parent"
    android:layout_marginRight="6dip"
    android:src="@drawable/icon" />
    <LinearLayout
    android:eek:rientation="vertical"
    android:layout_width="0dip"
    android:layout_weight="1"
    android:layout_height="fill_parent">
    <TextView
    android:id="@+id/toptext"
    android:layout_width="fill_parent"
    android:layout_height="0dip"
    android:layout_weight="1"
    android:gravity="center_vertical"
    />
    <TextView
    android:layout_width="fill_parent"
    android:layout_height="0dip"
    android:layout_weight="1"
    android:id="@+id/middletext"
    android:singleLine="true"
    android:ellipsize="marquee"
    />
    <TextView
    android:layout_width="fill_parent"
    android:layout_height="0dip"
    android:layout_weight="1"
    android:id="@+id/bottomtext"
    android:singleLine="true"
    android:ellipsize="marquee"
    />
    <TextView
    android:layout_width="fill_parent"
    android:layout_height="0dip"
    android:layout_weight="1"
    android:id="@+id/sidetext"
    android:singleLine="true"
    android:ellipsize="marquee"
    />
    </LinearLayout>
    </LinearLayout>
    ______________________________



    And where's its called in my Home Activity

    ______________________________
    private void showStatusItems(List<StatusContainer> list)
    {
    _loginLayout.setVisibility(View.INVISIBLE);
    _mainLayout.setVisibility(View.VISIBLE);


    ArrayAdapter<JobListAdaptor> listAdapter = new ArrayAdapter<JobListAdaptor>(this, R.layout.status_container_list_entry, StatusContainer.getStatusItemList());

    _statusContainerListView.clearChoices();
    _statusContainerListView.setAdapter(listAdapter);

    }
    ______________________________


    Any help or tips would be greatly appreciated..
     

    Advertisement

  2. alostpacket

    alostpacket Over Macho Grande?
    Rank:
    None
    Points:
    513
    Posts:
    7,972
    Joined:
    Nov 29, 2009

    Nov 29, 2009
    7,972
    3,603
    513
    Android App Developer
    NY
    You should extend BaseAdapter and not use an ArrayAdapter.

    Everything else looks ok though.

    From: ArrayAdapter | Android Developers

    You could also look into a CursorAdapter. There are lots of tutorials online about both too. An ArrayAdapter really isnt what you need for what it looks like you are trying to do.

    Minor nitpick: JobListAdaptor should be named something like "JobListObject" or "JobObj" as it's the object in the adapter, not an adapter itself. That might help you keep things straight in your head. If you're familiar with the MVC design pattern it's helpful to think of the adapter as an adapter to the MODEL.
     
  3. alostpacket

    alostpacket Over Macho Grande?
    Rank:
    None
    Points:
    513
    Posts:
    7,972
    Joined:
    Nov 29, 2009

    Nov 29, 2009
    7,972
    3,603
    513
    Android App Developer
    NY
    oh, and welcome to AF
     

Share This Page

Loading...