如何通过列表按钮外面的setView设置setVisibility? [英] How to setVisibility in a listview by a button outside it?

查看:106
本文介绍了如何通过列表按钮外面的setView设置setVisibility?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个自定义的Listview,其中连续有1个Button 我想在Listview外面添加一个按钮,以设置所有行上按钮的可见性 我该如何实现?

I have a custom Listview with 1 Button on a row I would like to add a button outside the Listview to set the visibility on button on all rows How can i achieve this?

我不想使用notifyDataSetChanged重新加载所有数据 有人知道吗?

And i DONT wanna use notifyDataSetChanged that reload all data Anyone got an idea of this??

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <TextView
        android:id="@+id/notice_title"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textColor="#000000"
        android:textSize="16dp" />

    <TextView
        android:id="@+id/notice_date"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/notice_title"
        android:textSize="8dp" />

    <ImageButton 
        android:id="@+id/btn_delete"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="@drawable/btn_delete"
        android:layout_alignParentRight="true"
        android:layout_alignParentBottom="true"
        android:visibility="invisible" />

</RelativeLayout>

Adapter_notice.java

Adapter_notice.java

public class Adapter_notice extends ArrayAdapter<notice> {

    private Context context; 
    private int listRow;    
    private notice[] notice; 
    public List<String> listTag = new ArrayList<String> ();


    public Adapter_notice(Context context, int listRow, notice[] Rows) {
        super(context, listRow, Rows);
        this.listRow = listRow;
        this.context = context;
        this.notice = Rows;

    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        View row;
        //Log.d("edittext", "items !empty="+listTag.contains(listTag.get(position)));
        LayoutInflater inflater = LayoutInflater.from(context);

            row = inflater.inflate(listRow,parent, false);
            notice row_notice = notice[position];
            TextView tv1 = (TextView) row.findViewById(R.id.notice_title);
            tv1.setText(row_notice.gettitle());
            TextView tv2 = (TextView) row.findViewById(R.id.notice_date);
            tv2.setText("Date:"+row_notice.getdate());
            ImageButton btn = (ImageButton) row.findViewById(R.id.btn_delete);

        return row;
    }
}

列表外按钮的onClick()中的

推荐答案

,执行

listview.setAdapter(changedAdapter) 

其中changedAdapter将是一组新的适配器或

Where changedAdapter will be a new set of adapter OR

    adapter.setButtonVisibility(false);
    listview.setAdapter(adapter). 

在Adapter类中创建一个新方法,该方法设置一个boolean值,getView将基于该方法返回视图(如果boolean为true,则Button字段将变为不可见)

Create a new method in your Adapter class which sets a boolean value based on which the getView will return view (if boolean is true, Button field will be made invisible)

public void setButtonVisibility(boolean hideButton){
    this.hideButton = hideButton;
}

getView(){
...
if(hideButton){
    //hide button
}
}

这篇关于如何通过列表按钮外面的setView设置setVisibility?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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