English 中文(简体)
如何在 ListView 中消失某个单元格
原标题:How to disappear some cell in ListView
@Override
public View getView(int position, View convertView, ViewGroup parent) {
    ViewTag viewTag;
    if(convertView == null) {
        convertView = myInflater.inflate(R.layout.row_item, null);
        viewTag = new ViewTag((LinearLayout)convertView.findViewById(R.id.row), (TextView)convertView.findViewById(R.id.tv));
        convertView.setTag(viewTag);
    }
    else {
        viewTag = (ViewTag) convertView.getTag();
    }

    viewTag.tv.setText(lvt.getTextAt(position));
    viewTag.tv.setVisibility(View.VISIBLE);

    boolean show = lvt.getShowAt(position);
    if(show) {
        viewTag.tv.setVisibility(View.GONE);
        viewTag.ll.setVisibility(View.GONE);
    }
    else {
        viewTag.ll.setVisibility(View.VISIBLE);
    }

    return convertView;
}

I use above code in BaseAdapter to show list view.
lvt is an application global data.
If show is true, I want to disappear the cell.
But not delete the data.
But my method will not show data, but show the divider line.
How can I do it?

最佳回答

我更改了以下数值 :

@Override
public int getCount() {
    int count = 0;
    int i;
    for(i = 0; i < lvt.sizeTestArray(); i++) {
        if(!lvt.getfiv1At(i)) {
            count++;
        }
    }
    return count;
}

并改变 GEView 的位置如下:

    int i;
    int count = 0;
    for(i = 0; i < lvt.sizeTestArray(); i++) {
        if(!lvt.getfiv1At(i)) {
            if(count == position) {
                position = i;
                break;
            }
            count++;
        }
    }

It seems do well now.
But I am not sure any bug exist now.

问题回答

如果您想要从 ListView 中 < em> 隐藏 < / em > 项目, 我更希望您使用 seperate < code> lvt (只显示真实), 而不是试图操纵视图 。

you can t do what you are asking for.
if BaseAdater.count() return the count of all the itmes(even the ones you don t want to show), than you can t tell the getView() method to "ignore" some of the logic items.

我建议你做的是过滤您的数据列表( 创建一个新的 lvt), 以便只对您想要列表View 显示的项目进行过滤, 并且只有到那时, 适配器才能使用这个新的逻辑数据 。

在您的情况中,正如您所怀疑的那样,“lvt.get SshowAt( 位置) =假”应该是您的过滤指示器





相关问题
Android - ListView fling gesture triggers context menu

I m relatively new to Android development. I m developing an app with a ListView. I ve followed the info in #1338475 and have my app recognizing the fling gesture, but after the gesture is complete, ...

AsyncTask and error handling on Android

I m converting my code from using Handler to AsyncTask. The latter is great at what it does - asynchronous updates and handling of results in the main UI thread. What s unclear to me is how to handle ...

Android intent filter for a particular file extension?

I want to be able to download a file with a particular extension from the net, and have it passed to my application to deal with it, but I haven t been able to figure out the intent filter. The ...

Android & Web: What is the equivalent style for the web?

I am quite impressed by the workflow I follow when developing Android applications: Define a layout in an xml file and then write all the code in a code-behind style. Is there an equivalent style for ...

TiledLayer equivalent in Android [duplicate]

To draw landscapes, backgrounds with patterns etc, we used TiledLayer in J2ME. Is there an android counterpart for that. Does android provide an option to set such tiled patterns in the layout XML?

Using Repo with Msysgit

When following the Android Open Source Project instructions on installing repo for use with Git, after running the repo init command, I run into this error: /c/Users/Andrew Rabon/bin/repo: line ...

Android "single top" launch mode and onNewIntent method

I read in the Android documentation that by setting my Activity s launchMode property to singleTop OR by adding the FLAG_ACTIVITY_SINGLE_TOP flag to my Intent, that calling startActivity(intent) would ...

From Web Development to Android Development

I have pretty good skills in PHP , Mysql and Javascript for a junior developer. If I wanted to try my hand as Android Development do you think I might find it tough ? Also what new languages would I ...

热门标签