spentak
spentak

Reputation: 4727

Android Subclass Listview problem

I have a subclass of ListView. My only problem is I can't get it to work (not the listview code, but the code to use the listview. Android won't inflate it (app crashes). I'm sure there is a simple way to get this to work, but I don't know how.

PullToRefreshListView list;

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) 
{
    super.onCreate(savedInstanceState);
    setContentView(R.layout.cliplistmain);

    context = this;
    list = (PullToRefreshListView)findViewById(R.id.clipListMain);
    list.setOnItemClickListener(this);
    list.setOnScrollListener(this);

    list.setOnRefreshListener(new OnRefreshListener(){
        @Override
        public void onRefresh() 
        {
            ClipStore.getInstance().getClips(SugarLoafContext.currentCamera);
        }
    });

    Button btn = (Button)findViewById(R.id.findclipsbtn);
    btn.setOnClickListener(this);
    SugarLoafContext.lastView = SugarLoafContext.LAST_VIEW_CLIP_LIST;

}

Here is my xml:

<ListView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/clipListMain" >

Upvotes: 1

Views: 1217

Answers (2)

buergi
buergi

Reputation: 6256

This is only a part of your layout xml file right, so you do have header and namespace information in your XML.

I guess you get a ClassCastException or similar right? Since you've got a ListView in your xml but cast it into your PullToRefreshListView class.

Your layout xml (i.e. ./res/layout/foo.xml) should be something like

<?xml version="1.0" encoding="utf-8"?>
<com.yourpackage.foo.PullToRefreshListView
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res/com.yourpackage.foo"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:id="@+id/clipListMain" />

Upvotes: 1

Codium
Codium

Reputation: 3240

IMO you forget about adding this subclass name to xml config

Upvotes: 1

Related Questions