java - How do you create a static table in Android? -
i new android programming ios , need create static table. simple in ios use of static cells there such thing in android?
to more precise of need, each row has 3 columns, textview name, edittext number of units , final textview number of units multiplied constant.
the way understand listview's in android need make custom adapter read in string constants strings.xml. if however, may able load table visually need it, when edittext value changed, how able handle , edit text of corresponding textview? need each row independent , able set id's every element in row can access , edit them doesn't seem possible reading in values string.xml.
sorry there no code given here, new android , don't know start. if please include code in answer, appreciated, thanks!
if size of table not known (and if known, still might preferable) it's best use listview (or recyclerview now, linearlayoutmanager).
a listview/recyclerview view of many items of same type of data. component binds each datum row, you've said, adapter.
with regards saving information user scrolls through list, should update data source. can done:
- immediately, after each piece of data entered
- as each row scrolls off screen, row data can saved (search for: on view recycled) + when user leaves screen
i'd recommend using recyclerview , extending recyclerview.adapter, can same thing listview , extending baseadapter, , quite easy switch between.
then i'd create model class represent each row: should include fields each of 3 columns, e.g.:
class item { private final string name; private final int units; private final int result; item(string name, int units, int result) { this.name = name; this.units = units; this.result = result; } string getname() { return name; } int getunits() { return units; } int getresult() { return result; } }
then adapter hold list<item>
field. note although result can calculated given unit , number of units, it's not responsibility of adapter - should pretty dumb, , consequently pretty simple, merely creating views when it's asked, , binding views item @ given position when it's asked too.
- another similar question op asked how edit items of listview (with listadapter) , persist changes user scrolled , down.
- listview, callback when view recycled (scrolled off screen)
- recyclerview, callback when view recycled
Comments
Post a Comment