Мое приложение получит SMS, сохранит его в SQLite и отобразит его в моем списке. Остальное сделано, но я не могу получить данные в свой список; как я могу это сделать?Как добавить в мой список из 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? – happydave
Для привязки данных с помощью ListView вам необходимо использовать адаптер Adorder. –
@happydave, пожалуйста, вы можете проверить мое обновление – Maha