加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

关于获取自定义控件(加减控件)及获取其中的子控件

发布时间:2020-12-16 06:20:30 所属栏目:百科 来源:网络整理
导读:目前写毕设的时候碰见自定义加减按钮效果图如下: 先说下自定义控件可以挺过自己写的一个累实现,只是在后来的布局XML文件中直接添加就好,例如,上图后面的点击按钮 数量增减,我在这自定义控件为add_sub控件在list.xml 就可以直接使用了,eg : i

目前写毕设的时候碰见自定义加减按钮效果图如下:


先说下自定义控件可以挺过自己写的一个累实现,只是在后来的布局XML文件中直接添加就好,例如,上图后面的点击按钮 数量增减,我在这自定义控件为add_sub控件在list.xml 就可以直接使用了,eg :index_detail_item.xml

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="horizontal" >

    <ImageView
        android:id="@+id/seller_image"
        android:layout_width="0dp"
        android:layout_height="fill_parent"
        android:scaleType="fitStart"
        android:layout_gravity="left"
        android:layout_weight="1"
         />

    <TextView
        android:id="@+id/seller_name"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1.5"
         
           />

    <TextView
        android:id="@+id/seller_money"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="0.5"
        android:text="TextView" />
   <myself.add_sub 
        android:id="@+id/seller_number"
        android:layout_width="0dp"
        android:layout_gravity="start"
        android:layout_height="wrap_content"
        android:layout_weight="1"/>
 

</LinearLayout>
 其中add_sub 直接当控件使用。 
 

要获取控件中的数量则需要使用如下代码:

final View layout2=inflater.inflate(R.layout.index_detail_item)(父控件布局),
(ViewGroup) layout.findViewById(R.id.seller_number)---自定义控件);
final EditText numEditText=(EditText)layout2.findViewById(R.id.num);

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读