在ListView的行号行号、ListView

2023-09-08 00:22:31 作者:你只是我的奴り

我有一个ListView从源码中读取数据SimpleCursorAdapter和表有1000行,但我已经过滤在我的活动按日期我的名单,所以过滤的游标包含两行的特殊day.Therefor我想对,我已经因子评分我的list.one soloution添加自定义行号(不能使用_id),是ViewBinder,这里是我的code:

  adapter.setViewBinder(新ViewBinder(){
    公共布尔setViewValue(查看诚挚的范例,光标aCursor,诠释aColumnIndex){
        如果(aColumnIndex == 0){
            aCursor.moveToFirst();
            如果(aCursor.moveToFirst()){
                TextView中的TextView =(TextView中)诚挚的范例;
                textView.setText(+ WeeklyListRowNumber);
                WeeklyListRowNumber = WeeklyListRowNumber + 1;
            }
            返回true;
        }
        返回false;
    }
});
 

我在我名单11列和WeeklyListRowNumber初始化1在上面,我的问题是我rownumbers变成7,8,但它必须是1,2,可有人告诉我我该怎么解决这个问题呢?

解决方案

 公开查看getView(INT位置,查看convertView,ViewGroup中父){
        查看RETVAL = NULL;

            RETVAL = LayoutInflater.from(parent.getContext())。膨胀(
                    R.layout.content,NULL);

            标题=(TextView中)retval.findViewById(R.id.contactName);
            数=(TextView中)retval.findViewById(R.id.contactNumber);
            title.setText(文字,在列表中显示);
            number.setText(+位置); //添加行号列出//固定变量
        }
 

如何修改Excel中的行号和列标

I have a ListView that reads data from sqlite with SimpleCursorAdapter and the table has about 1000 rows but i've filtered my list in my Activity by date, so the filtered cursor contains 2 rows for that special day.Therefor i wanted to add a custom row number(can't use _id) for my list.one soloution that i've tought about,was ViewBinder, here is my code:

adapter.setViewBinder(new ViewBinder() {
    public boolean setViewValue(View aView, Cursor aCursor, int aColumnIndex) {
        if (aColumnIndex == 0) {
            aCursor.moveToFirst();
            if(aCursor.moveToFirst()) {
                TextView textView = (TextView) aView;
                textView.setText("" + WeeklyListRowNumber);
                WeeklyListRowNumber = WeeklyListRowNumber + 1;
            }
            return true;
        }
        return false;
    }
});

I have 11 columns in my List and WeeklyListRowNumber initialized 1 on the top,my problem is my rownumbers turns to 7,8 but it must be 1 , 2.can somebody tells me how can I solve this issue?

解决方案

public View getView(int position, View convertView, ViewGroup parent) {
        View retval = null;

            retval = LayoutInflater.from(parent.getContext()).inflate(
                    R.layout.content, null);

            title = (TextView) retval.findViewById(R.id.contactName);
            number = (TextView) retval.findViewById(R.id.contactNumber);
            title.setText(text to display in list);
            number.setText(""+position);//add row number to list //fixed the variable
        }