from the WebServer i can fetch data and pass it correctly into ListView with this class:
ReceiveFields
class Structure:
public class ReceiveFields {
public long lastId;
public String smsNumber;
public String mobileNumber;
public String senderName;
public String smsBody;
public String receiveDate;
private Context ctx;
}
ReceivedSMS
Class to get data from WebService:
public class ReceivedSMS extends ListFragment implements AbsListView.OnScrollListener {
private List<ReceiveFields> rows;
private int prevVisibleItem;
private TSMS tsms;
private String username;
private String password;
public Long getLastReceivedSMSID;
private boolean isFirstTime;
private Context context;
public ResivedSMS(Context context, String username, String password) {
this.username = username;
this.password = password;
this.context = context;
}
public ResivedSMS(String username, String password, long start, long count,Context context) {
this.username = username;
this.password = password;
this.context = context;
tsms = new TSMS(context ,new User(username, password));
getResivedSMS(start , count);
}
public ResivedSMS(List<ReceiveFields> receivedSMSList,Context context){
rows = receivedSMSList;
this.context = context;
}
public List<ReceiveFields> getResivedSMS(long start, long count) {
tsms = new TSMS(context,new User(this.username, this.password));
try {
rows = tsms.getReceivedSMS(start, count);
}
catch (TException e) {
e.printStackTrace();
Log.e("ERROR IN Fetch SMS From WebService List<ReceiveFields> getResivedSMS(long start, long count) " , String.valueOf(e));
}
return rows;
}
use ResivedSMS class as :
ResivedSMS receivedSMSList = new ReceivedSMS("username","password",0,20,context);
and pass into ListView :
getSupportFragmentManager().beginTransaction().replace(R.id.drawer, receivedSMSList).commit();
all of this way is correct and i dont have problem. but i want to fetch data from DataBase and pass it insted of ReceivedSMS as :
List<ReceiveFields> r1 = db.getAllReceivedSMSFromDatabase();
receivedSMSList = new ResivedSMS(r1,context);
getSupportFragmentManager().beginTransaction().replace(R.id.drawer, receivedSMSList).commit();
getAllReceivedSMSFromDatabase
function :
public List<ReceiveFields> getAllReceivedSMSFromDatabase() {
SQLiteDatabase db = this.getReadableDatabase();
String selectQuery = "SELECT * FROM " + this.RECEIVE_FIELDS_TABLE ;
Cursor cursor = db.rawQuery(selectQuery, null);
List<ReceiveFields> ListSMS = new ArrayList<ReceiveFields>();
cursor.moveToFirst();
while (cursor.moveToNext()) {
ListSMS.add(new ReceiveFields(
Long.valueOf(cursor.getString(cursor.getColumnIndex("lastId"))),
cursor.getString(cursor.getColumnIndex("smsNumber")),
cursor.getString(cursor.getColumnIndex("mobileNumber")),
cursor.getString(cursor.getColumnIndex("senderName")),
cursor.getString(cursor.getColumnIndex("smsBody")),
cursor.getString(cursor.getColumnIndex("receiveDate"))));
}
cursor.close();
db.close();
return ListSMS;
}
NOTE: My Database is not empty and have 20 rows
getAllReceivedSMSFromDatabase
return value is like with getResivedSMS
but i get this error :
getAllReceivedSMSFromDatabase
Function Result with `LogCat:
ID: 19 lastId: 29901991 smsNumber: 30007227 mobileNumber: 09000000892 senderName 09122510892 smsBody: tsssasaS receiveDate: 2014/8/3
ID: 19 lastId: 29901992 smsNumber: 30007227 mobileNumber: 09000000892 senderName 09122510892 smsBody: tsssasaS receiveDate: 2014/9/3
ID: 19 lastId: 29901993 smsNumber: 30007227 mobileNumber: 09000000892 senderName 09122510892 smsBody: tsssasaS receiveDate: 2014/10/3