我有两个不同页面的1.list show和2.item show的列表视图,我想获取特定列表的项目页面中的项目数,并在textview中显示计数。实际上,我从光标得到了listview的计数,但它也显示了其他列表列中的所有项目计数。任何人都可以帮我找到特定项目的计数。谢谢提前。
1.db class
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.mainclass
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();
}
答案 0 :(得分:0)
lv1.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
String retieveValue = lv1.getAdapter().getItem(position).toString();
//display value here
}
});
基于retieveValue,您可以从数据库中获取数据,以便将数据放入其他列表视图中。
答案 1 :(得分:0)
对于您的情况,请尝试以下代码
1.sqlite
public static Cursor remindervalues(int id, int id1){
Cursor cur=db.rawQuery(" SELECT * FROM "+ Contactsnew.TABLE03 + " WHERE "
+ Contactsnew.listId + " = " + id + " AND " + Contactsnew.userId1 + "=" + id1,
null);
return cur;
}
2.在你的适配器类
Cursor cur = SQLiteConnectornew.remindervalues(id,id1);
if(cur!=null){
cur.moveToFirst();
str = cur.getCount();
Log.d("vaal", String.valueOf(str));
}
String xurva = String.valueOf(str);
//curval.setText(xurva + "/" + "0");
cur.close();