I have an activity that contains a List. This list will take the data from SQLite:
public class RecentCases extends Activity {
Button GoToCaseInfo, CreateNewFormB;
RecentCaseClass recent1;
// the adapter class..
class RecentCasesInfoAdapter extends ArrayAdapter<RecentCaseClass>
{
public RecentCasesInfoAdapter() {
super(RecentCases.this, R.layout.recent_cases_row);
}
public View getView(final int position, View convertView,
ViewGroup parent)
{
recent1 = this.getItem(position);
LayoutInflater inflater = getLayoutInflater();
View row = inflater.inflate(R.layout.recent_cases_row, parent,
false);
// this is our row items..
TextView recentName = (TextView) row
.findViewById(R.id.tvrecentName);
TextView recenInfo = (TextView) row.findViewById(R.id.recent_info);
ImageView recentImg = (ImageView) row.findViewById(R.id.list_image);
// TODO What's the info they want
// String CaseTime = recent1.getTime();
// recentName.setText(recent1.getName());
// recenInfo.setText("His/her age: " + recent1.getAge() +
// " year old"
// + " Lost sicnce :" + CaseTime);
String CasePicPath;
// TODO Linear or ??
RelativeLayout rowLayout = (RelativeLayout) row.findViewById(R.id.row_layout);
rowLayout.setOnClickListener(new View.OnClickListener() {
public void onClick(View arg0) {
// TODO Auto-generated method stub
// go to
Intent k = new Intent(RecentCases.this, Case_Information.class);
startActivity(k);
}
});
return row;
}
}
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.recent_cases);
// Moving to Create New Form Activity
CreateNewFormB = (Button) findViewById(R.id.cretnwfrmRC);
CreateNewFormB.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Intent k = new Intent(RecentCases.this, CreateNewForm.class);
startActivity(k);
}
});
// For list
// Intilaize
ListView RecentCasesListView = (ListView) findViewById(R.id.recent_cases_list);
// create adapter
RecentCasesInfoAdapter recentCasesInfoAdapter = new RecentCasesInfoAdapter();
// 1-First receives MMS OnReceive Class 2- Assign the MMS info to Static
// Array 3- Assign the array to the adapater
// for(MedicineClass m: Model.getMedList()) MedicineInfoAdapter.add(new
// MedicineClass(m));
recentCasesInfoAdapter.add(recent1);
// after fill the adapter.. assign the list to the adapter
RecentCasesListView.setAdapter(recentCasesInfoAdapter);
}
}
and this is the class
public class RecentCaseClass {
private String pic;
private String name;
private String gender;
private int age;
private String clothes;
private String MoreInfo;
private String time;
private String location;
private int ID;
public String getPic() {
return pic;
}
public void setPic(String pic) {
this.pic = pic;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getGender() {
return gender;
}
public void setGender(String gender) {
this.gender = gender;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public String getClothes() {
return clothes;
}
public void setClothes(String clothes) {
this.clothes = clothes;
}
public String getMoreInfo() {
return MoreInfo;
}
public void setMoreInfo(String moreInfo) {
MoreInfo = moreInfo;
}
public String getTime() {
return time;
}
public void setTime(String time) {
this.time = time;
}
public String getLocation() {
return location;
}
public void setLocation(String location) {
this.location = location;
}
public int getID() {
return ID;
}
public void setID(int iD) {
ID = iD;
}
}
The SMS will come to my app then i will save in SQLite then i should show it in my app
- How can i take data from SQLite and show it in list?
- If I delete the row information from SQLite how can i delete the row in list?
- Should i change the adapter?
============================UPDATE===========================
I add this to my project but I did not change any thing just added this class:
public class RecentClassAdapter extends BaseAdapter{
private RecentCases RecentCases;
static public List<RecentCaseClass> listOfRCases;
RecentCaseClass entry;
int caseId;
public RecentClassAdapter(RecentCases recentcases, List<RecentCaseClass> listOfCaseParameter) {
this.RecentCases = recentcases;
this.listOfRCases = listOfCaseParameter;
}
public int getCount() {
return listOfRCases.size();
}
public Object getItem(int position) {
return listOfRCases.get(position);
}
public long getItemId(int position) {
return position;
}
public View getView(int position, View convertView, ViewGroup viewGroup) {
entry = listOfRCases.get(position);
caseId = entry.getID();
if (convertView == null) {
LayoutInflater inflater = (LayoutInflater) RecentCases.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = inflater.inflate(R.layout.recent_cases_row, null);
}
// this is row items..
// Set the onClick Listener on this button
//ConfExpandRegion = (Button) convertView.findViewById(R.id.expand);
//Button Cancelb = (Button) convertView.findViewById(R.id.cancelCase);
TextView RCase = (TextView) convertView.findViewById(R.id.tvrecentName);
RCase.setText(entry.getName());
Toast.makeText(RecentCases, "inside getview" + entry.getAge(), 0).show();
public void add(RecentCaseClass RCaseClass) {
// TODO Auto-generated method stub
listOfRCases.add(RCaseClass);
}
}
}