• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps Getting Strings from SQLite and Putting Them on String Array

I got the list set up. But the problem is that the list only display the last inputted data...

Code:
public class View extends ListActivity {
    
    TextView SQLinfo;
    String[] data = null;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        setContentView(R.layout.view);
        
        SQLinfo = (TextView) findViewById(R.id.SQLinfo);
        DatabaseH info = new DatabaseH(this);
        info.open();
        data = info.getData();
        info.close();
        
        setListAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, data));

    }
    
    @Override
    protected void onListItemClick(ListView l, android.view.View v,
            int position, long id) {
        // TODO Auto-generated method stub
        super.onListItemClick(l, v, position, id);
        
        if (position == 0) {
            SQLinfo.setText("hi");
        }
    }
}
Code:
public String[] getData() {
        
        String[] columns = new String[] { KEY_ROWID, KEY_SUBJECT, KEY_MSG};
        Cursor c = ourDatabase.query(DATABASE_TABLE, columns, null, null, null, null, null);
        String result = "";
        
        int iRow = c.getColumnIndex(KEY_ROWID);
        int iSubj = c.getColumnIndex(KEY_SUBJECT);
        int iMsg = c.getColumnIndex(KEY_MSG);
        
        for (c.moveToFirst(); !c.isAfterLast(); c.moveToNext()) {
            //result = result + c.getString(iRow) + " " + c.getString(iSubj) + " " + c.getString(iMsg) + "\n";
            result = c.getString(iSubj);
            
        }
        
        String[] array = result.split(" ");
        return array;
    }
 
Back
Top Bottom