【发布时间】:2012-05-09 01:24:38
【问题描述】:
我的应用程序将接收短信,将其保存在 SQLite 中,然后将其显示在我的列表中。 其余的都完成了,但我无法将数据放入我的列表中;我该怎么做?
这是我正在尝试的:
list.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> arg0, View view,
int position, long index) {
// here send Recent case Object OR or Recent case info. to show case information
}
});
这是我的适配器:
public class RecentCaseListAdapter extends BaseAdapter {
private RecentCases myPage;
static public List<RecentCaseClass> listOfCases;
RecentCaseClass entry;
public RecentCaseListAdapter(RecentCases R, List<RecentCaseClass> listOfCaseParameter) {
this.myPage = R;
this.listOfCases = listOfCaseParameter;
}
public int getCount() {
return listOfCases.size();
}
public Object getItem(int position) {
return listOfCases.get(position);
}
public long getItemId(int position) {
return position;
}
public View getView(int position, View convertView, ViewGroup viewGroup) {
entry = listOfCases.get(position);
if (convertView == null) {
LayoutInflater inflater = (LayoutInflater) myPage.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
TextView tvCase = (TextView) convertView.findViewById(R.id.tvrecentName);
tvCase.setText(entry.getName());
TextView tvCaseInfo = (TextView) convertView.findViewById(R.id.recent_info);
tvCaseInfo.setText(entry.getAge());
// To be a clickable button
return convertView;
}
public void add(RecentCaseClass rCaseClass) {
// TODO Auto-generated method stub
listOfCases.add(rCaseClass);
}
}
这是我的清单
public static List<RecentCaseClass> RecentCaseList = new ArrayList<RecentCaseClass>();
public static List<RecentCaseClass> getRecentCaseList() {
return RecentCaseList;
}
public static void setRecentCaseList(List<RecentCaseClass> recentCaseList) {
RecentCaseList = recentCaseList;
}
我应该在哪里添加列表
if (SMSReceived.startsWith("Hi")) {
Toast.makeText(context, "Iam in hi", Toast.LENGTH_LONG)
.show();
msg = SMSReceived;
RecentCaseClass rCase = run();
dbAdapter.add(rCase);
All_Static.RecentCaseList.add(recent1);
}
【问题讨论】:
-
您是否想了解如何从 SQLite 表中获取数据到 ListView 中?我不清楚你在哪个方面遇到了麻烦。您是否尝试过使用 SimpleCursorAdapter?
-
您需要使用适配器才能将数据与 ListView 绑定。
-
@happydave 请检查我的更新
-
@ShashankKadne 你能检查我的编辑吗