1. Download our Official Android App: Forums for Android!

Apps Getting Strings from SQLite and Putting Them on String Array

Discussion in 'Android Development' started by ContemPlato, Sep 13, 2011.

  1. ContemPlato

    ContemPlato Lurker
    Thread Starter
    Rank:
    None
    Points:
    5
    Posts:
    3
    Joined:
    Sep 13, 2011

    Sep 13, 2011
    3
    0
    5
    I got the list set up. But the problem is that the list only display the last inputted data...

    Code (Text):
    1. public class View extends ListActivity {
    2.    
    3.     TextView SQLinfo;
    4.     String[] data = null;
    5.  
    6.     @Override
    7.     protected void onCreate(Bundle savedInstanceState) {
    8.         // TODO Auto-generated method stub
    9.         super.onCreate(savedInstanceState);
    10.         setContentView(R.layout.view);
    11.        
    12.         SQLinfo = (TextView) findViewById(R.id.SQLinfo);
    13.         DatabaseH info = new DatabaseH(this);
    14.         info.open();
    15.         data = info.getData();
    16.         info.close();
    17.        
    18.         setListAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, data));
    19.  
    20.     }
    21.    
    22.     @Override
    23.     protected void onListItemClick(ListView l, android.view.View v,
    24.             int position, long id) {
    25.         // TODO Auto-generated method stub
    26.         super.onListItemClick(l, v, position, id);
    27.        
    28.         if (position == 0) {
    29.             SQLinfo.setText("hi");
    30.         }
    31.     }
    32. }
    Code (Text):
    1. public String[] getData() {
    2.        
    3.         String[] columns = new String[] { KEY_ROWID, KEY_SUBJECT, KEY_MSG};
    4.         Cursor c = ourDatabase.query(DATABASE_TABLE, columns, null, null, null, null, null);
    5.         String result = "";
    6.        
    7.         int iRow = c.getColumnIndex(KEY_ROWID);
    8.         int iSubj = c.getColumnIndex(KEY_SUBJECT);
    9.         int iMsg = c.getColumnIndex(KEY_MSG);
    10.        
    11.         for (c.moveToFirst(); !c.isAfterLast(); c.moveToNext()) {
    12.             //result = result + c.getString(iRow) + " " + c.getString(iSubj) + " " + c.getString(iMsg) + "\n";
    13.             result = c.getString(iSubj);
    14.            
    15.         }
    16.        
    17.         String[] array = result.split(" ");
    18.         return array;
    19.     }
     

    Advertisement

Share This Page

Loading...