I have a problem in adding values to my String[] array from another class. What I wanted to do is to add values to my MainScreenEntered.java class from database through my MyDatabaseAdapter.java class.
PLease help.
THis is my code.
MainScreenentered.java
public class MainScreenEntered extends Activity implements OnItemClickListener{
@SuppressLint("NewApi")
ListView lv;
List<RowItem> rowItems;
MyDatabaseAdapter mh;
String username;
ListView listViewSMS;
Cursor cursor;
Context context;
public static String[] names = new String[] {};
public static String[] descriptions = new String[] {};
public static String[] pics = new String[] {};
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main_screen_entered);
mh = new MyDatabaseAdapter(this);
Bundle bundle = this.getIntent().getExtras();
username = bundle.getString("username");
Message.message(this, username);
try
{
mh.getDataToDatabase();
rowItems = new ArrayList<RowItem>();
for(int i =0; i< names.length; i++)
{
RowItem item = new RowItem(pics[i], names[i], descriptions[i]);
rowItems.add(item);
}
lv = (ListView)findViewById(R.id.lvEntries);
CustomListViewAdapter adapter = new CustomListViewAdapter(this, R.layout.list_layout,rowItems);
lv.setAdapter(adapter);
lv.setOnItemClickListener(this);
}
catch(Exception e)
{
Message.message(this, ""+e);
}
}
}
MyDatabaseAdapter.java
public class MyDatabaseAdapter {
MyHelper helper;
public MyDatabaseAdapter (Context context)
{
helper = new MyHelper(context);
}
public void getDataToDatabase()
{
MainScreenEntered ms = new MainScreenEntered();
SQLiteDatabase db = helper.getWritableDatabase();
String columns[] = {MyHelper.ENTRY_FULLNAME,MyHelper.ENTRY_DESCRIPTION,MyHelper.ENTRY_IMAGE};
Cursor c=db.query(MyHelper.TABLE_ENTRIES, columns, null, null, null, null, null);
int i=0;
while(c.moveToNext())
{
String name = c.getString(0);
String desc = c.getString(1);
String pic = c.getString(2);
ms.names[i] = name;
ms.descriptions[i] = desc;
ms.pics[i] = pic;
i++;
}
db.close();
}
}