gpt4 book ai didi

java - SQLite 与列表

转载 作者:行者123 更新时间:2023-12-01 15:23:41 25 4
gpt4 key购买 nike

我有一个包含列表的 Activity 。此列表将从 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);

}
}

这就是类(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;
}

}

短信将发送到我的应用程序,然后我将保存在 SQLite 中,然后我应该在我的应用程序中显示它

  1. 如何从 SQLite 获取数据并将其显示在列表中?
  2. 如果我从 SQLite 中删除行信息,如何删除列表中的行?
  3. 我应该更换适配器吗?

==============================更新================== =========

我将其添加到我的项目中,但我没有更改任何内容,只是添加了此类:

        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);
}


}

}

最佳答案

您必须创建一个自定义数组适配器,并从数据库中逐行获取数据,并使用 getView 方法填充到 Listview 中。

这是自定义数组适配器的示例

http://android-er.blogspot.in/2010/06/custom-arrayadapter-with-with-different.html

http://www.ezzylearning.com/tutorial.aspx?tid=1763429&q=customizing-android-listview-items-with-custom-arrayadapter

关于java - SQLite 与列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10494619/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com