How to get all child views at runtime?

private void forWebviews() {

	final ViewGroup viewGroup = (ViewGroup) ((ViewGroup) this
			.findViewById(android.R.id.content)).getChildAt(0);
			
	int elementSize = getWenViews(viewGroup).size();
	for(int j =0; j< elementSize;j++)
	{			
		WebView getAllWebView = formIsValid(viewGroup).get(j);
		String SplitTypeWebView = String.valueOf(getAllWebView);
		String getWebValues = getAllWebView.getUrl().toString();
		SplitWebViewID(SplitTypeWebView);
	 }	
}

private ArrayList<WebView> getWenViews(ViewGroup viewGroup) {
	
	ArrayList<WebView> webview = new ArrayList<WebView>();
	for (int i = 0; i < viewGroup.getChildCount(); i++) {
		View v = viewGroup.getChildAt(i);
		if (v instanceof WebView) {
			webview.add((WebView) v);
		}
	}
	return webview;
}



<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="com.example.dmp_webview.MainActivity"
    android:orientation="vertical">
   
	   <WebView
	        android:id="@+id/simpleWebView"
	        android:layout_width="fill_parent"
	        android:layout_height="fill_parent"
	        android:layout_marginTop="20dp"
	        android:scrollbars="none" />
	   
	   <WebView
	        android:id="@+id/simpleWebView2"
	        android:layout_width="fill_parent"
	        android:layout_height="fill_parent"
	        android:layout_marginTop="20dp"
	        android:scrollbars="none" />
</LinearLayout>

**I try to get all the Webview elements in current activity at the time loading and i get the output.BUT when i one more **
LinearLayout(Not only linearlayout other layouts also) for webview parent means like this,

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="com.example.dmp_webview.MainActivity"
    android:orientation="vertical">
   
	<LinearLayout
        android:layout_width="match_parent"
	    android:layout_height="match_parent"
	    android:background="#ffffff"
	    android:orientation="vertical"
	    android:padding="16dp"
	    android:id="@+id/RootLayout_1">
	    
		   <WebView
				android:id="@+id/simpleWebView"
				android:layout_width="fill_parent"
				android:layout_height="fill_parent"
				android:layout_marginTop="20dp"
				android:scrollbars="none" />
		   
		   <WebView
				android:id="@+id/simpleWebView2"
				android:layout_width="fill_parent"
				android:layout_height="fill_parent"
				android:layout_marginTop="20dp"
				android:scrollbars="none" />
				
	 </LinearLayout>
	 
</LinearLayout>

Its not working properly. why? plz guide me.Actually i get root layout and itrate over.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.