Page 134

Android Programming Cookbook

package com.javacodegeeks.AndroidStackViewActivity; import android.app.Activity; import android.os.Bundle; import android.widget.StackView; import java.util.ArrayList; public class AndroidStackViewActivity extends Activity { private static StackView stackView; private static ArrayList list; private static final Integer[] icons = {R.drawable.jellybean, R.drawable.kitkat, R.drawable.lollipop, R.drawable.marshmellow, R.drawable.nougat}; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); stackView = (StackView) findViewById(R.id.stack_view); list = new ArrayList(); for (int i = 0; i < icons.length; i++) { list.add(new StackItems("Item " + i, icons[i])); } StackAdapter adapter = new StackAdapter(AndroidStackViewActivity.this, list); stackView.setAdapter(adapter); adapter.notifyDataSetChanged(); } }

7.7

AndroidManifest.xml

The AndroidManifest.xml of our project has no special permissions. AndroidManifest.xml <manifest xmlns:android="https://schemas.android.com/apk/res/android" package="com.javacodegeeks.AndroidStackViewExample"> <application android:allowBackup="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:supportsRtl="true" android:theme="@style/AppTheme"> <activity android:name=".AndroidStackViewActivity" android:label="@string/app_name" android:screenOrientation="portrait"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application> </manifest >

126 / 143

SKY MAGZ  

This is Yahya Christian School Magazine