I have an Activity which also has a ListView in it. I’m loading some EditText boxes, buttons, etc to that ListView in my getView method.
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);
}
And in multiple instances I’m also adding a Button to the same List. Basically, I’m just loading a particular layout file to a particular row based on the row index of the ListView. The button has the id button_title – defined in my xml below.
convertView = mInflater.inflate(R.layout.next, null); *//inside getView method*
Contents of 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>
Now, since I have multiple instances of the same button within this activity, I’m not able to assign unique IDs to each of these buttons. All buttons technically now hold the same ID.
Is there any way in which I can assign different IDs to each of these buttons? Programmatically?
You need to use findViewById on the buttons parent layout in order to change the id on the specific button.
Egs:
Notice findViewById is used on the convertView…