I am creating widget for my application. i downloaded the LoremWidget project from github. link is here
here one array named items. when i hardcoded the array it will display values in widget correctly. but it does not show any thing when i try to fetch the data from database and copied the data to array by element by element. i given the Write and Read permission to manifest file.can any one find my errors pls. but i used this database code to another application (not widget) its retrieving correctly.
LoremViewsFactory.java
public class LoremViewsFactory extends Activity implements RemoteViewsService.RemoteViewsFactory
{
public String[] items = new String[10];
private Context ctxt = null;
private int appWidgetId;
public LoremViewsFactory(Context ctxt, Intent intent) {
int i = 0;
DatabaseHandler db = new DatabaseHandler(LoremViewsFactory);
List < Contact > contacts = db.getAllContacts();
for (Contact cn: contacts) {
String log = cn.getURL();
Toast.makeText(LoremViewsFactory.this, log, Toast.LENGTH_LONG).show();
items[i] = log;
i++;
}
this.ctxt = ctxt;
appWidgetId = intent.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID,
AppWidgetManager.INVALID_APPWIDGET_ID);
}
This my getAllContactsfunction DatabseHandler class
public List < Contact > getAllContacts() {
List < Contact > contactList = new ArrayList < Contact > ();
String selectQuery = "SELECT * FROM " + TABLE_CONTACTS;
SQLiteDatabase db = this.getWritableDatabase();
Cursor cursor = db.rawQuery(selectQuery, null);
if (cursor.moveToFirst()) {
do {
Contact contact = new Contact();
contact.setURL(cursor.getString(0));
// Adding contact to list
contactList.add(contact);
} while (cursor.moveToNext());
}
return contactList;
}
}