Hello, forum, Vaironl here:
I been researching( not some good research) on how to use a listview because I'm getting multiple things from my database and displaying them in multiple rows, as if it was the table itself.
But I believe I'm both not reading right and not using the array right. Can someone give me some help I'm fairly new to android.
Info class which uses the ListArray
Databasehelper getWhen method
I been researching( not some good research) on how to use a listview because I'm getting multiple things from my database and displaying them in multiple rows, as if it was the table itself.
But I believe I'm both not reading right and not using the array right. Can someone give me some help I'm fairly new to android.
Info class which uses the ListArray
Code:
package com.DCWebMakers.Vairon;
import java.util.List;
import android.app.Activity;
import android.content.Intent;
import android.database.DataSetObserver;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.TextView;
public class MyAppointment extends Activity {
ListView whenLi, postedLi, detailsLi, editLi, removeLi;
ListAdapter whenAdapter, postedAdapter, detailsAdapter, editAdapter,
removeAdapter;
String[] test = new String[] { "value1", "value2" };
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.my_appointment);
initVariables();
AppointmentInfo information = new AppointmentInfo(this);
information.open();
String when[] = information.getWhen();
information.close();
whenAdapter = new ArrayAdapter<String>(this, R.id.whenList, when);
whenLi.setAdapter(whenAdapter);
}
public void initVariables() {
whenLi = (ListView) findViewById(R.id.whenList);
postedLi = (ListView) findViewById(R.id.postedList);
detailsLi = (ListView) findViewById(R.id.detailsList);
editLi = (ListView) findViewById(R.id.editList);
removeLi = (ListView) findViewById(R.id.removeList);
}
@Override
protected void onPause() {
// TODO Auto-generated method stub
super.onPause();
Intent mainIntent = new Intent("com.DCWebMakers.Vairon.MAINMENU");
startActivity(mainIntent);
}
@Override
protected void onResume() {
// TODO Auto-generated method stub
super.onResume();
}
@Override
protected void onRestoreInstanceState(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onRestoreInstanceState(savedInstanceState);
}
@Override
protected void onSaveInstanceState(Bundle outState) {
// TODO Auto-generated method stub
super.onSaveInstanceState(outState);
}
}
Databasehelper getWhen method
Code:
public String[] getWhen() {
// TODO Auto-generated method stub
String[] columns = new String[] { KEY_WHEN };
Cursor cursor = theDatabase.query(DATABASE_TABLE, columns, null, null,
null, null, null);
int iWhen = cursor.getColumnIndex(KEY_WHEN);
int arrayLenght = 0;
for (cursor.moveToFirst(); !cursor.isAfterLast(); cursor.moveToNext()) {
arrayLenght++;
}
String[] whenValues = new String[arrayLenght];
arrayLenght=0;
for (cursor.moveToFirst(); !cursor.isAfterLast(); cursor.moveToNext()) {
whenValues[arrayLenght] = cursor.getString(iWhen);
arrayLenght++;
}
return whenValues;
}