开发者

Creating some kind of table for user data

I am working on my first Android application, and I have run into a brick wall. It would be easier to explain if you saw this picture of the main screen first: http://patmahoneyjr.com/wp-content/uploads/2011/08/App-main-screen.png

When a user clicks the new category button, a dialog box comes up and they have to enter a name and select a percent via a SeekBar. After that, they click enter. I used Intents to get the data from one place to another.

Now, I don't know how to correctly handle it. What I would like to do is create a table of some kind beneath the b开发者_StackOverflow中文版uttons and for each time that they click the enter button in the new category dialog, create a new row on the table consisting of the name of the category, the percent chosen, and then the amount of the paycheck that is equal to that percent. I have a crude drawing of how that would sort of look here (WARNING: I USED MICROSOFT PAINT ;) http://patmahoneyjr.com/wp-content/uploads/2011/08/App-main-screen1.png

After that, a user enters the amount of their paycheck using the new paycheck button, and that number is divided amongst the categories, and displayed.

Now, this being my first app, of course I ran into trouble here. I have absolutely no idea how to do this. Any bits of advice or code is of course greatly appreciated!

Thanks!


What I would do in this situation is add a ListView to your main layout xml under the two buttons. Then create another layout xml file with a RelativeLayout containing two TextViews. Make sure the RelativeLayout has layout_width="fill_parent" and layout_height="wrap_content". You can align the two TextViews like in your picture. Use this layout file for the items in your ListView.

Next you probably want to store your data somewhere, an SQLite database would be best. Use a CursorAdapter to get the data from the database to the list, and use the following CursorAdapter methods when data is added to the database:

  • swapCursor(newCursor) - gives the Adapter the new Cursor you get when you requery the database after adding an item
  • notifyDataSetChanged() - refreshes the ListView.

Alternativley, you could use a custom Loader, which makes handling Cursors and dynamic data a little easier.

I recommend you start by looking at these tutorials and articles:

http://developer.android.com/resources/tutorials/views/hello-listview.html

http://developer.android.com/guide/topics/data/data-storage.html

http://developer.android.com/resources/tutorials/notepad/index.html


I suggest you work through the Notepad tutorial to learn the basics on lists and databases. That should get you started.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜