views:

12

answers:

1

Is there anyway I can create a dynamically filled ListView when the class does not extend ListActivity?

I appreciate the help.

+2  A: 

Yes. Example:

public class StoreListActivity extends Activity {
    private List<Store> mStores;
    private StoreAdapter mStoreAdapter;
    private ListView mListView;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.store_list);
        mListView = (ListView) findViewById(R.id.store_listview);

            mStores = getTheStoresFromSomewhere();
        mStoreAdapter = new StoreAdapter(this, mStores);
        mListView.setAdapter(mStoreAdapter);
    }
Macarse
Could an array adapter be used as-well?
Mitchell
@Mitchell: Yes.
CommonsWare
:D Got it working. Thanks everyone! Although I might have another question which I'll post later.
Mitchell
@Mitchell: Actually `StoreAdapter extends ArrayAdapter<Store>`
Macarse