处理按钮事件列表视图问题的每行中 [英] Handling button event in each row of Listview issue

查看:175
本文介绍了处理按钮事件列表视图问题的每行中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新来的Andr​​oid和正在试图建立一个新的Andr​​oid应用程序。但是我在努力siolve在我的项目的问题之一。

I am new to android and am trying to develop a new android app. But I am struggling to siolve one of the problems in my project.

我使用的 baseadapter 扩展列表视图,需要thelistview的每一行中添加一个按钮。当我点击在ListView的任何行的按钮,我想它应该被删除。然而,当我这样做,其他的一些按钮也得到了列表视图中删除。

I am using a listview extended from baseadapter and need to add a button in each row of thelistview. When I click on the button in any row of the listview, I want that it should be removed. However when I do so, some of the other buttons also get removed in the listview.

我该如何解决这个问题呢?谢谢。

How can I solve this problem? Thank you..

推荐答案

您有一个适配器,活动和某种类型的数据源

You have an adapter, activity and some sort of data source

在您的适配器您可以将一些数据按钮,可以告诉从另一个:

In your adapter you attach some data to buttons to be able to tell one from another:

public class ExpAdapter extends ListAdapter {

    @Override
    public View getView(int groupPosition, boolean isExpanded,
            View convertView, ViewGroup parent) {
                /* SOME CODE HERE*/
        convertViewButton.setTag(buttonId);
        return convertView;
    }
                /* SOME CODE HERE*/
}

在您的活动您标记按钮ID作为一个被隐藏的:

in your activity you mark button id as the one to be hidden:

        public boolean onItemLongClick(AdapterView<?> arg0, View arg1,
                int arg2, long arg3) {
            storageOfHiddenButtonsIds.add((Long)arg1.getTag());
        }};

和这样便ListAdapter变化:

and then ListAdapter changes like this:

@Override
public View getView(int groupPosition, boolean isExpanded,
        View convertView, ViewGroup parent) {
            /* SOME CODE HERE*/

    convertViewButton.setTag(buttonId);

    if(storageOfHiddenButtonsIds.contains(buttonId))
    {
      convertViewButton.setVisiblity(View.GONE);
    }
    return convertView;
}

,当你希望你的adatper改变你,不要忘了叫

and when you want your adatper to change you, don't forget to call

this.expAdapterAllTaks.notifyDataSetChanged();

对不起,在我的code任何错误,但我只是想给你出个主意。

Sorry for any errors in my code, but i just wanted to give you an idea.

这篇关于处理按钮事件列表视图问题的每行中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆