android -> parent control traverses child controls

 

layout file: 

<LinearLayout android:id="@+id/candi_more_row1"
	android:orientation="horizontal"
	android:gravity="center_vertical"
	android:layout_width="match_parent"
	android:layout_weight="1"
	android:layout_height="match_parent">
	<View
		android:layout_marginTop="5dip"
		android:layout_marginBottom="5dip"
		android:background="#BDBDBD"
		android:layout_width="1px"
		android:layout_height="match_parent"/>
	<Button
		android:onClick="onClick"
		android:textSize="@dimen/candi_box_btn_font_size"
		android:id="@+id/candi_more_row1_1"
		android:tag="panelCandiBtn_1"
		android:text="Water and electricity"
		android:textColor="#474747"
		android:background="@drawable/keyb_none_bg"
		android:layout_weight="1"
		android:layout_width="match_parent"
		android:layout_height="match_parent" />
	<View
		android:layout_marginTop="5dip"
		android:layout_marginBottom="5dip"
		android:background="#BDBDBD"
		android:layout_width="1px"
		android:layout_height="match_parent"/>
	<Button
		android:onClick="onClick"
		android:textSize="@dimen/candi_box_btn_font_size"
		android:id="@+id/candi_more_row1_2"
		android:tag="panelCandiBtn_2"
		android:text="Water and electricity"
		android:textColor="#474747"
		android:background="@drawable/keyb_none_bg"
		android:layout_weight="1"
		android:layout_width="match_parent"
		android:layout_height="match_parent" />
	<View
		android:layout_marginTop="5dip"
		android:layout_marginBottom="5dip"
		android:background="#BDBDBD"
		android:layout_width="1px"
		android:layout_height="match_parent"/>
	<Button
		android:onClick="onClick"
		android:textSize="@dimen/candi_box_btn_font_size"
		android:id="@+id/candi_more_row1_3"
		android:tag="panelCandiBtn_3"
		android:text="Water and electricity"
		android:textColor="#474747"
		android:background="@drawable/keyb_none_bg"
		android:layout_weight="1"
		android:layout_width="match_parent"
		android:layout_height="match_parent" />
	<View
		android:layout_marginTop="5dip"
		android:layout_marginBottom="5dip"
		android:background="#BDBDBD"
		android:layout_width="1px"
		android:layout_height="match_parent"/>
	<Button
		android:onClick="onClick"
		android:textSize="@dimen/candi_box_btn_font_size"
		android:id="@+id/candi_more_row1_4"
		android:tag="panelCandiBtn_4"
		android:text="Water and electricity"
		android:textColor="#474747"
		android:background="@drawable/keyb_none_bg"
		android:layout_weight="1"
		android:layout_width="match_parent"
		android:layout_height="match_parent" />
	<View
		android:layout_marginTop="5dip"
		android:layout_marginBottom="5dip"
		android:background="#BDBDBD"
		android:layout_width="1px"
		android:layout_height="match_parent"/>
	<Button
		android:onClick="onClick"
		android:textSize="@dimen/candi_box_btn_font_size"
		android:id="@+id/candi_more_row1_5"
		android:tag="panelCandiBtn_5"
		android:text="Water and electricity"
		android:textColor="#474747"
		android:background="@drawable/keyb_none_bg"
		android:layout_weight="1"
		android:layout_width="match_parent"
		android:layout_height="match_parent" />
	<View
		android:layout_marginTop="5dip"
		android:layout_marginBottom="5dip"
		android:background="#BDBDBD"
		android:layout_width="1px"
		android:layout_height="match_parent"/>
</LinearLayout>

 

 

JAVA

LinearLayout lt = (LinearLayout)keyboard_view_zh.findViewById(R.id.candi_more_row1);
for (int i = 0;i < lt.getChildCount(); i++){
	if (lt.getChildAt(i) instanceof Button) { // If Button records
		Button tb = (Button)lt.getChildAt(i);
		tb.setText("L:"+i);
	}
}

 

 

 

 

 

 

 

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326273141&siteId=291194637