1

我有两个列表视图用于 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();
        }
4

2 回答 2

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 ,您可以从数据库中获取数据以将数据放入其他列表视图。

于 2013-08-17T09:45:54.763 回答
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();
于 2013-09-06T08:27:18.917 回答