Java tutorial
package com.kawunglabs.olimpiadeuiapp; //import android.app.ListActivity; //import android.content.Intent; //import android.os.Bundle; //import android.support.v4.app.NavUtils; //import android.util.Log; //import android.view.Menu; //import android.view.MenuItem; //import android.view.View; //import android.widget.ArrayAdapter; //import android.widget.ListView; // //public class HelpActivity extends ListActivity { // private String[] daftarFAQ = { // "1. Melihat Jadwal Pertandingan", // "2. Melihat Hasil Pertandingan", // "3. Melihat Perolehan Medali", // "4. Menyaring Pertandingan Berdasarkan Fakultas", // "5. Membagikan Informasi Melalui Twitter" // }; // // private int[] gambar = { // R.drawable.help_schedule, // R.drawable.help_past, // R.drawable.help_upcoming, // R.drawable.help_match, // R.drawable.help_group, // R.drawable.help_knockout, // R.drawable.help_medals, // R.drawable.help_filter, // R.drawable.help_about // }; // // @Override // protected void onCreate(Bundle savedInstanceState) { // super.onCreate(savedInstanceState); // setContentView(R.layout.activity_help); // // ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, // android.R.layout.simple_list_item_1, daftarFAQ); // // setListAdapter(adapter); // } // // @Override // public boolean onCreateOptionsMenu(Menu menu) { // // Inflate the menu; this adds items to the action bar if it is present. // getMenuInflater().inflate(R.menu.help, menu); // return true; // } // // @Override // public boolean onOptionsItemSelected(MenuItem item) { // switch (item.getItemId()) { // case android.R.id.home: // // This ID represents the Home or Up button. In the case of this // // activity, the Up button is shown. Use NavUtils to allow users // // to navigate up one level in the application structure. For // // more details, see the Navigation pattern on Android Design: // // // // http://developer.android.com/design/patterns/navigation.html#up-vs-back // // // NavUtils.navigateUpFromSameTask(this); // return true; // } // return super.onOptionsItemSelected(item); // } // // @Override // public void onListItemClick(ListView l, View v, int position, long id) { // Intent intent = new Intent(this, HelpGuide.class); // Log.d("posisi", position + ""); // intent.putExtra("gambarHelp", gambar[position]); // startActivity(intent); // } //} /* * Copyright 2012 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import android.app.ActionBar; import android.content.pm.ActivityInfo; import android.content.res.Resources; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.os.Bundle; import android.support.v4.app.Fragment; import android.support.v4.app.FragmentActivity; import android.support.v4.app.FragmentManager; import android.support.v4.app.FragmentStatePagerAdapter; import android.support.v4.view.ViewPager; import android.view.LayoutInflater; import android.view.MenuItem; import android.view.View; import android.view.ViewGroup; import android.widget.ImageView; public class HelpActivity extends FragmentActivity { /** * The {@link android.support.v4.view.PagerAdapter} that will provide fragments representing * each object in a collection. We use a {@link android.support.v4.app.FragmentStatePagerAdapter} * derivative, which will destroy and re-create fragments as needed, saving and restoring their * state in the process. This is important to conserve memory and is a best practice when * allowing navigation between objects in a potentially large collection. */ DemoCollectionPagerAdapter mDemoCollectionPagerAdapter; /** * The {@link android.support.v4.view.ViewPager} that will display the object collection. */ ViewPager mViewPager; private static Resources resources; private static String[] pageTitle = { "Jadwal", "Hasil", "Medali", "Fakultas", "Share" }; private static int[] helpImage = { R.drawable.help_jadwal, R.drawable.help_hasil, R.drawable.help_medali, R.drawable.help_fakultas, R.drawable.help_share }; public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); setContentView(R.layout.activity_help); resources = getResources(); // Create an adapter that when requested, will return a fragment representing an object in // the collection. // // ViewPager and its adapters use support library fragments, so we must use // getSupportFragmentManager. mDemoCollectionPagerAdapter = new DemoCollectionPagerAdapter(getSupportFragmentManager()); // Set up action bar. final ActionBar actionBar = getActionBar(); // Specify that the Home button should show an "Up" caret, indicating that touching the // button will take the user one step up in the application's hierarchy. actionBar.setDisplayHomeAsUpEnabled(true); // Set up the ViewPager, attaching the adapter. mViewPager = (ViewPager) findViewById(R.id.pager); mViewPager.setAdapter(mDemoCollectionPagerAdapter); } @Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case android.R.id.home: // This ID represents the Home or Up button. In the case of this // activity, the Up button is shown. Use NavUtils to allow users // to navigate up one level in the application structure. For // more details, see the Navigation pattern on Android Design: // // http://developer.android.com/design/patterns/navigation.html#up-vs-back // // NavUtils.navigateUpFromSameTask(this); onBackPressed(); return true; } return super.onOptionsItemSelected(item); } /** * A {@link android.support.v4.app.FragmentStatePagerAdapter} that returns a fragment * representing an object in the collection. */ public static class DemoCollectionPagerAdapter extends FragmentStatePagerAdapter { public DemoCollectionPagerAdapter(FragmentManager fm) { super(fm); } @Override public Fragment getItem(int i) { Fragment fragment = new DemoObjectFragment(); Bundle args = new Bundle(); Bitmap image = BitmapFactory.decodeResource(resources, helpImage[i]); args.putParcelable(DemoObjectFragment.HELP_IMAGE, image); fragment.setArguments(args); return fragment; } @Override public int getCount() { // For this contrived example, we have a 100-object collection. return pageTitle.length; } @Override public CharSequence getPageTitle(int position) { return pageTitle[position]; } } /** * A dummy fragment representing a section of the app, but that simply displays dummy text. */ public static class DemoObjectFragment extends Fragment { public static final String HELP_IMAGE = "help_image"; @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View rootView = inflater.inflate(R.layout.activity_help_guide, container, false); Bundle args = getArguments(); Bitmap bitmap = args.getParcelable(HELP_IMAGE); ImageView imageView = (ImageView) rootView.findViewById(R.id.gambarHelp); imageView.setImageBitmap(bitmap); return rootView; } } }