Code example for ViewPager

Methods: addViewaddView

0
 
			String pos = String.valueOf(position);
			//String filename = type + "story" + pos + ".txt"; 
			//String contentStr = ""; 
 
			ScrollView sv = new ScrollView(cxt);
 
			LinearLayout ll = new LinearLayout(cxt);
			ll.setOrientation(LinearLayout.VERTICAL);
 
			TextView tv = new TextView(cxt);
			tv.setText("This is page # " + position);
			tv.setTextColor(Color.WHITE);
			tv.setTextSize(30);
 
			ll.addView(tv);
 
			/* 
			InputStream input; 
			try { 
				input = getAssets().open(filename); 
				if (input != null) { 
					// prepare the file for reading 
					InputStreamReader inputreader = new InputStreamReader(input); 
					BufferedReader buffreader = new BufferedReader(inputreader); 
					String line; 
 
					while ((line = buffreader.readLine()) != null) { 
						contentStr += line + '\n'; 
					} 
					 
					TextView cont = new TextView(cxt); 
					cont.setTextColor(Color.BLACK); 
					cont.setTextSize(20); 
					cont.setTypeface(Typeface.createFromAsset(getAssets(), 
							"fonts/textfont.ttf")); 
					cont.setText(contentStr); 
					ll.addView(cont); 
 
				} 
				input.close(); 
			} catch (IOException e) { 
				e.printStackTrace(); 
			} 
			*/ 
			 
			TextView cont = new TextView(cxt);
			cont.setTextColor(Color.BLACK);
			cont.setTextSize(20);
			//cont.setTypeface(Typeface.createFromAsset(getAssets(), 
			//		"fonts/fontw3.ttc")); 
			 
			if (type.equals("mood"))
				cont.setText(moodstrs[position]);
			else if (type.equals("family"))
				cont.setText(familystrs[position]);
			else if (type.equals("grow"))
				cont.setText(growstrs[position]);
			 
			ll.addView(cont);
 
			sv.addView(ll);
			((ViewPager) collection).addView(sv);
			return sv;
		} 
 
		/** 
		 * Remove a page for the given position. The adapter is responsible for 
Connect your IDE to all the code out there  Get Codota for Java