java - how to set id for android datagrid? -


guys trying create data grid using edittextand tablelayout in android project have been successful in creating ui edittext require setting id each field.

enter image description here want set id r1c1,r1c2... etc or there better way it. want calculate row total , column total.

edit: have add button generates new row. cells generated programmatically.

table cell snippet:

    edittext cb= new edittext(this);     cb.setlayoutparams(params);     cb.setbackgroundcolor(color.parsecolor("#ffffff")); 

i don't think there's way strings "r1c1", "r1c2" etc, there couple of options:

if need valid id, use static method view.generateviewid(). api level 17 though, work in recent versions of android. see here:
http://developer.android.com/reference/android/view/view.html#generateviewid%28%29

an alternative store references edittext objects in two-dimensional array or list. when need sum rows or columns, you'd iterate on appropriate section of array , go there.

a third option keep two-dimensional array of values each edittext instead of edittext itself. textwatcher this:

// creating edittext (row,col) // expand size of 2d array if necessary edittext cb = new edittext(this); cb.setlayoutparams(params); cb.setbackgroundcolor(color.parsecolor("#ffffff")); cb.setinputtype(inputtype.type_class_number); // user can enter numbers cb.addtextchangedlistener(new textwatcher() {   public void aftertextchanged(editable s) {     mvalues[row][col] = integer.valueof(s.tostring());   } }); 

see these links more details:
https://developer.android.com/reference/android/widget/textview.html#addtextchangedlistener%28android.text.textwatcher%29
https://developer.android.com/reference/android/text/textwatcher.html


Comments

Popular posts from this blog

Change php variable from jquery value using ajax (same page) -

Pull out data related to my apps from Android Play Store and iOS App Store -

How can I fetch data from a web server in an android application? -