Page 145

Android Programming Cookbook

137 / 143

import android.view.ViewGroup; import android.widget.ImageView; import android.widget.TextView; public class FragmentViewPager extends android.support.v4.app.Fragment { @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View v = inflater.inflate(R.layout.fragment_main, container, false); TextView tv = (TextView) v.findViewById(R.id.title); tv.setText(getArguments().getString("text")); ImageView imageView = (ImageView) v.findViewById(R.id.image); imageView.setBackgroundResource(getArguments().getInt("img")); return v; } public static FragmentViewPager newInstance(String text, int image) { FragmentViewPager f = new FragmentViewPager(); Bundle b = new Bundle(); b.putString("text", text); b.putInt("img", image); f.setArguments(b); return f; } }

8.6

Android Manifest

The AndroidManifest.xml of our project is simple and contains the main Activity of our example: AndroidManifest.xml <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="https://schemas.android.com/apk/res/android" package="com.javacodegeeks.examples.androidViewPagerExample" > <application android:allowBackup="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:theme="@style/AppTheme" > <activity android:name=".AndroidViewPagerExample" android:label="@string/app_name" > <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application> </manifest

â&#x2020;?-

SKY MAGZ  

This is Yahya Christian School Magazine

Read more
Read more
Similar to
Popular now
Just for you