views:

53

answers:

1

I'm pretty new to java programming and am looking to do basic data mappings. I have a ListView object with a simple data array setup like this:

setListAdapter(new ArrayAdapter<String>(this, R.layout.my_list_xml, MY_DATA));

What I want to happen is when you click an item it goes to it's subcategory. I'm not worried about switching the data when an item is clicked. I'm just not sure how to create the data set in an efficient way using Android. Eventually this will be driven by a database but I want to figure out how to use mock-data to get this working first. An example of what I need the data structure will be is like:

myData = { 'category1' => 
            { 'subcategory1' => 'subcategorydetail1', 
              'subcategory2' => 'subcategorydetail2'},
           'category2' => 
            { 'subcategory3' => 'subcategorydetail3', 
              'subcategory4' => 'subcategorydetail4'}
       }

I'd like to be able to access it like myData['category2'] or myData['category2']['subcategory3']

Should I create this in xml files and link them up or is it best to create a new class structure for it?

Thanks for your help!

A: 

If eventually this app'll display data from a local SQLite database, then I think you'd be better off designing those DB schemas, filling the resulting tables up with mock data, and using that. The reason is, that you should write custom CursorAdapter classes for filling up your ListViews with data coming from the DB (from cursors), and those are a bit different than adapters extending BaseAdapter - which you'd have to use if you fill up those lists with common objects.

This way you might be able to evade the tedious task of mapping data from the DB to objects - tho that depends on what you'd like to do what that data.

Scythe
Yeah it really needs to be dynamic as possible because the data structure is going to be different based on 10+ implementations. I'll look into the CursorAdapter though. Thanks!
wajiw