Hi I wanna generate dynamic labels which are names of patients fetched from database at run time and also wanna generate 2 dynamic buttons and a check box in front of the labels. Please correct my code if necessary and also please provide me code to perform the actions i specified. And if you could please also help me by providing xml code.
My code is as below:
package com.minorproject.mobilehealthcaremanagementsystem;
import android.app.Activity;
import android.content.res.Resources;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.graphics.drawable.Drawable;
import android.view.ViewGroup.LayoutParams;
import android.widget.*;
import java.util.*;
import android.os.Bundle;
public class ViewDynamicActivity extends Activity {
ArrayList<TableRow> tablerowlist;
ArrayList<CheckBox> cblist;
ArrayList<Button> buttonlist;
ArrayList<TextView> textviewlist;
LinearLayout ll;
ScrollView sv;
TableLayout tablelayout;
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
tablerowlist=new ArrayList<TableRow>();
cblist=new ArrayList<CheckBox>();
textviewlist=new ArrayList<TextView>();
buttonlist=new ArrayList<Button>();
tablelayout=new TableLayout(this);
ll=new LinearLayout(this);
sv=new ScrollView(this);
LayoutParams param=new LayoutParams(LayoutParams.FILL_PARENT,
LayoutParams.WRAP_CONTENT);
tablelayout.setLayoutParams(param);
SQLiteDatabase db=openOrCreateDatabase("MinorDatabase.sqlite", MODE_PRIVATE, null);
Cursor c=db.rawQuery("select patientid from patientdetailtable", null);
//how can i store patient id in an int variable
if(c.moveToNext())
{
for(int i=0;i<c;i++) /*Also how can i compare the i with patient id value in database*/
{
tablerowlist.add(new TableRow(this));
cblist.add(new CheckBox(this));
textviewlist.add(new TextView(this));
buttonlist.add(new Button(this));
tablerowlist.get(i).addView(cblist.get(i));
tablerowlist.get(i).addView(textviewlist.get(i));
tablerowlist.get(i).addView(buttonlist.get(i));
tablelayout.addView(tablerowlist.get(i));
}
}
ll.addView(tablelayout);
sv.addView(ll);
setContentView(sv);
}
}
Aucun commentaire:
Enregistrer un commentaire