View Single Post
Old August 5th, 2009, 04:47 PM   #3 (permalink)
skatalicious
New Member
 
Join Date: Aug 2009
Posts: 3
 
Device(s):
Thanks: 0
Thanked 0 Times in 0 Posts
Default With help from others, I got it working

With help from Mark on the 'Android Beginners' Google group, I was able to get it working.

Here is what I did, also referencing GTalk :: anddev.org - Android Development Community | Android Tutorials.

Code:
public class testListView extends ListActivity {
  ...
  private DecimalFormat myCustDecFormatter = new DecimalFormat("########.00");
  ...
  ...
  /** Called when the activity is first created. */
  @Override
  public void onCreate(Bundle savedInstanceState)  {
    ...
    ...
    ...
  }

private void fillData() {
    /* Get all of the rows from the database and create the item list */
    /* for mult accts, pass in acct name? */
    mEntryCursor = mDbHelper.fetchAllEntries();
    startManagingCursor(mEntryCursor);
    
    // Create an array to specify the fields we want to display in the list (only TITLE)
    String[] from = new String[]{myDbAdapter.KEY_NMBR,myDbAdapter.KEY_DATE,myDbAdapter.KEY_DESCR,myDbAdapter.KEY_AMT};
    
    // and an array of the fields we want to bind those fields to (in this case just text1)
    int[] to = new int[]{R.id.txtnmbr, R.id.txtdate, R.id.txtdescr, R.id.txtamt};
    
    // Now create a simple cursor adapter and set it to display
    setListAdapter(new SimpleCursorAdapter(this, R.layout.entryrow, mEntryCursor, from, to) {
        @Override
        public void setViewText(TextView v, String text) {
          super.setViewText(v, convText(v, text));
        }
        
    });
     
  }
  
  private String convText(TextView v, String text) {
    switch (v.getId()) {
      case R.id.txtamt:
        double dblAmt;
        //dblAmt = Double.valueOf(text);
        dblAmt = mEntryCursor.getDouble(AMT_COLUMN);
        return myCustDecFormatter.format(dblAmt);
    }
      return text;
    } 
...
...
...
}//end testListView
skatalicious is offline  
Last edited by skatalicious; August 5th, 2009 at 04:50 PM.
Reply With Quote