我有两个列表视图用于 1.list 显示和 2.item 显示在两个不同的页面中,我想获取特定列表的项目页面中的项目数并在 textview 中显示计数。实际上,我从光标中获得了列表视图的计数,但它也显示了其他列表列中的所有项目计数。谁能帮我找到特定项目的计数。提前致谢。
1.db类
public void insertContact1(int _id3, int _id4, String content,boolean deleteflag, boolean updateflag, boolean reminder) {
// TODO Auto-generated method stub
ContentValues cv = new ContentValues();
cv.put(Contactsnew.listId, _id3);
cv.put(Contactsnew.userId1, _id4);
cv.put("CONTENT", content);
cv.put(Contactsnew.DELETE_FLAG, deleteflag);
cv.put(Contactsnew.UPDATE_FLAG, updateflag);
cv.put(Contactsnew.REMINDER, reminder);
db = sqlHp.getWritableDatabase();
db.insert(Contactsnew.TABLE3, null, cv);
}
public void updateContact1(int _id3, int _id4, String content,boolean deleteflag, boolean updateflag) {
// TODO Auto-generated method stub
ContentValues cv = new ContentValues();
cv.put(Contactsnew.listId, _id3);
cv.put(Contactsnew.userId1, _id4);
cv.put("CONTENT", content);
cv.put(Contactsnew.DELETE_FLAG, deleteflag);
cv.put(Contactsnew.UPDATE_FLAG, updateflag);
//db.insert(Contactsnew.TABLE03, null, cv);
db = sqlHp.getWritableDatabase();
db.update(Contactsnew.TABLE3, cv, Contactsnew.listId + "=" + _id3,null);
db.close();
}
public static Cursor getcursorvalues(){
Cursor cur = db.query(Contactsnew.TABLE3, new String[] {Contactsnew.userid,Contactsnew.listId,Contactsnew.CONTENT},
null, null, null, null, null);
if(cur!=null){
cur.moveToFirst();
int str = cur.getCount();
Log.d("vaal", String.valueOf(str));
}
return cur;
}
2.主类
bt2.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
final String category2 = sp.getString("category", null);
if(clicked){
clicked = false;
ArrayList<String> newlist = new ArrayList<String>();
TextView curval;
for (int i = 0; i < getListView().getCount(); i++) {
v = getListView().getChildAt(i);
curval = (TextView) v.findViewById(R.id.cursorvalue);
curval.setText(" Edit");
}
}
else
{
clicked = true;
ArrayList<String> newlist = new ArrayList<String>();
TextView curval;
for (int i = 0; i < getListView().getCount(); i++) {
v = getListView().getChildAt(i);
curval = (TextView) v.findViewById(R.id.cursorvalue);
curval.setText(" 0/0");
value();
}
}
}
private void value() {
// TODO Auto-generated method stub
Cursor cur = SQLiteConnectornew.getcursorvalues();
if(cur==null){
Log.d("null", "null");
}
else{
Log.d("returnvalue", "returnvalue");
}cur.close();
}