首页 > 其他分享 >listView获得CheckBox 的位置

listView获得CheckBox 的位置

时间:2023-06-20 22:08:13浏览次数:32  
标签:box listView layout vi 位置 CheckBox null View


当一个lsitView中每个ietm有多个控件的时候想获得其中的位置,其实主要是item的位置

@Override 
public View getView(int position, View convertView, ViewGroup parent) { 
 
// grab view 
View v = convertView; 
// set view layout 
if (v == null) { 
    LayoutInflater vi = (LayoutInflater)getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
    v = vi.inflate(R.layout.layout_inbox_item, null); 
 
    CheckBox box = (CheckBox)v.findViewById(R.id.inbox_itemcheck); 
    if (box != null) { 
        box.setTag(position); //<-- sets the tag by its position 
        box.setOnCheckedChangeListener(new CheckBox.OnCheckedChangeListener() { 
                public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { 
                    int position = (Integer)buttonView.getTag(); //<-- get the position 
                } 
            }); 
    } 
} 
2.View getView(int position, View convertView, ViewGroup parent) { 
 
    // grab view 
    View v = convertView; 
    // set view layout 
    if (v == null) { 
        LayoutInflater vi = (LayoutInflater)getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
        v = vi.inflate(R.layout.layout_inbox_item, null); 
 
        CheckBox box = (CheckBox)v.findViewById(R.id.inbox_itemcheck); 
        if (box != null) { 
            box.setOnCheckedChangeListener(new CheckBox.OnCheckedChangeListener() { 
                    public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { 
                        ViewGroup v = (ViewGroup)buttonView.getParent().getParent(); 
                        int i = v.indexOfChild((View)buttonView.getParent()); 
                    } 
                }); 
        } 
    }

标签:box,listView,layout,vi,位置,CheckBox,null,View
From: https://blog.51cto.com/u_16166892/6525356

相关文章

  • listView中item 图文并存的两种方法
    1.<?xmlversion="1.0"encoding="utf-8"?><TextViewxmlns:android="http://schemas.android.com/apk/res/android"android:id="@android:id/text1"android:layout_width="fill_parent"......
  • listView显示选择图片
    publicclassItemsListextendsListActivity{privateItemsAdapteradapter;@OverrideprotectedvoidonCreate(BundlesavedInstanceState){super.onCreate(savedInstanceState);setContentView(R.layout.items_list);this.adapter=......
  • 步进电机T型算法基于stm32 步进电机T型运动控制器源码 输入脉冲数量 脉冲频率即可求出
    步进电机T型算法基于stm32步进电机T型运动控制器源码输入脉冲数量脉冲频率即可求出绝对位置相对位置,附带限位功能等。支持100khz。这段话涉及到的知识点和领域范围是步进电机控制、T型算法、STM32微控制器、脉冲数量、脉冲频率、绝对位置、相对位置和限位功能。步进电机是一......
  • SAP Commerce Cloud SolrIndexNotFoundException 异常 - 做 full indexing 的详细位置
    Console看到消息:NoActiveindexfound,FULLindexeroperationmustbeperformedbeforeanyotheroperationCausedby:de.hybris.platform.solrfacetsearch.solr.exceptions.SolrIndexNotFoundException:de.hybris.platform.servicelayer.exceptions.UnknownIdentifie......
  • 内核启动阶段获得dtb位置指针过程
    一.内核启动阶段获得dtb位置指针以arm64为例,内核启动如下:/arch/arm64/kernel/head.S __HEAD_head: /* *DONOTMODIFY.ImageheaderexpectedbyLinuxboot-loaders. */#ifdefCONFIG_EFI /* *Thisaddinstructionhasnomeaningfuleffectexceptthat *its......
  • echart折线图点击事件包括任意位置
    echart折线图点击事件包括任意位置一、常规点击事件在echarts中可以使用on为图形添加点击事件,但是这种方式添加的点击事件,只有点击在图形元素上才会触发事件处理函数。myChart.on('click',params=>{//可以设置点击的类型与响应的系列if(params.seriesType==='line'){......
  • c# listview
     1、属性CheckBoxes ture表头显示checkHideSelection失去焦点后选中的依然有区别2、           listView1.View=View.Details; //这样才能显示           this.listView1.Columns.Add("测试项",100,HorizontalAlignment.Left);     ......
  • 写一个删除列表中重复元素的函数,要求去重后元素相对位置保持不变
    1#无集合setlist_=['a','a','b','b','c','c']list_new=[]foriinlist_:ifinotinlist_new:list_new.append(i)list_newdeffun_1(list_=['a','a','b'......
  • 获取文件位置
    传入参数:stringname        stringfileName;        fileName.resize(MAX_PATH);        ::GetModuleFileName(NULL,const_cast<char*>(fileName.c_str()),MAX_PATH);         fileName=fileName.substr(static_cast<string::size......
  • qt——自己手动添加菜单栏、工具栏(自定义菜单栏、工具栏的位置)
    参考:原文链接 不一定非要用QGroupBox,其他继承自widget的控件都可以我的实现: ......