
if(position==0) { ((TextVIEw)convertVIEw.findVIEwByID(R.ID.textvIEw_settings)).setText("User information"); } else if(position==1 || position==2 || position==5 || position==6 || position==7 || position==10 || position==13) { ((linearLayout)convertVIEw.findVIEwByID(R.ID.linear_settings)).setVisibility(VIEw.VISIBLE); ((relativeLayout)convertVIEw.findVIEwByID(R.ID.relative_home)).setVisibility(VIEw.GONE); if(position==1 || position==5 || position==5) ((EditText)convertVIEw.findVIEwByID(R.ID.edittext_settings)).setBackgroundResource(R.drawable.f_t_1_iphone); else if(position==7 || position==2) ((EditText)convertVIEw.findVIEwByID(R.ID.edittext_settings)).setBackgroundResource(R.drawable.f_t_3_iphone); else if(position==6) ((EditText)convertVIEw.findVIEwByID(R.ID.edittext_settings)).setBackgroundResource(R.drawable.f_t_2_repeat_iphone); else if(position==13 || position==10) ((EditText)convertVIEw.findVIEwByID(R.ID.edittext_settings)).setBackgroundResource(R.drawable.f_t_4_iphone); } 在多个实例中,我也在同一个List中添加一个button.基本上,我只是根据ListVIEw的行索引将特定的布局文件加载到特定的行.该按钮具有ID button_Title – 在我的下面的xml中定义.
convertVIEw = mInflater.inflate(R.layout.next,null); *//insIDe getVIEw method*
next.xml的内容:
<?xml version="1.0" enCoding="utf-8"?><linearLayout xmlns:androID="http://schemas.androID.com/apk/res/androID" androID:layout_wIDth="fill_parent" androID:layout_height="fill_parent" androID:ID="@+ID/linear"> <FrameLayout androID:layout_wIDth="fill_parent" androID:layout_height="wrap_content" androID:ID="@+ID/frame_settings"> <relativeLayout androID:layout_wIDth="fill_parent" androID:layout_height="wrap_content" androID:ID="@+ID/relative_home" androID:orIEntation="horizontal" > <TextVIEw androID:ID="@+ID/textvIEw_settings" androID:layout_wIDth="wrap_content" androID:layout_height="wrap_content" androID:layout_gravity="center|left" androID:layout_margin="5dp" androID:text="" androID:textSize="15dp" androID:textStyle="bold" androID:typeface="sans" androID:layout_alignParentleft="true"/> <Imagebutton androID:ID="@+ID/button_Title" androID:layout_wIDth="wrap_content" androID:layout_height="wrap_content" androID:layout_gravity="left" androID:layout_marginRight="10dp" androID:background="@drawable/edit_button_pressed" androID:layout_alignParentRight="true"/> </relativeLayout> <linearLayout androID:ID="@+ID/linear_settings" androID:layout_wIDth="fill_parent" androID:layout_height="wrap_content"> <EditText androID:ID="@+ID/edittext_settings" androID:layout_wIDth="fill_parent" androID:layout_height="wrap_content" androID:textSize="12dp" androID:textStyle="bold" androID:typeface="sans" androID:layout_alignParentleft="true"/> </linearLayout> </FrameLayout> </linearLayout>
现在,由于此活动中有多个相同按钮的实例,因此我无法为每个按钮分配唯一的ID.从技术上讲,所有按钮现在都具有相同的ID.
有什么方法可以为每个按钮分配不同的ID?编程?
解决方法 您需要在按钮父布局上使用findVIEwByID才能更改特定按钮上的ID.EGS:
convertVIEw = mInflater.inflate(R.layout.next,null);button buttonIWanttochangeID = convertVIEw.findVIEwByID(R.whatever.button_Title);buttonIWanttochangeID.setID(1000+Listposition);
注意findVIEwByID用于convertVIEw …
总结以上是内存溢出为你收集整理的android – 在布局中多次使用相同的视图全部内容,希望文章能够帮你解决android – 在布局中多次使用相同的视图所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)