0% found this document useful (0 votes)
92 views

XML Version Encoding XMLNS: Package :name : Android

The document contains code for an Android app manifest file and a MainActivity Java file. The manifest requests permissions for location access and external storage. It defines one activity as the launcher with label "GEO-HLC". The MainActivity creates a ViewPager and SectionsPagerAdapter to display 6 fragments/tabs. It sets up the TabLayout with the ViewPager. The adapter returns a different fragment for each tab position.

Uploaded by

a
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
92 views

XML Version Encoding XMLNS: Package :name : Android

The document contains code for an Android app manifest file and a MainActivity Java file. The manifest requests permissions for location access and external storage. It defines one activity as the launcher with label "GEO-HLC". The MainActivity creates a ViewPager and SectionsPagerAdapter to display 6 fragments/tabs. It sets up the TabLayout with the ViewPager. The adapter returns a different fragment for each tab position.

Uploaded by

a
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

Android Manifest.

xml

<?xml version="1.0" encoding="utf-8"?>


<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="geothermal.tab_heatloss02">

<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"
/>
<uses-permission
android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission
android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="Heatloss Calculator"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity
android:name=".MainActivity"
android:label="GEO-HLC"
android:theme="@style/AppTheme.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER"
/>
</intent-filter>
</activity>
</application>

</manifest>

MainActivity. Java

package geothermal.tab_heatloss02;

import android.support.design.widget.TabLayout;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;

import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;

import android.widget.TextView;

public class MainActivity extends AppCompatActivity {

/**
* The {@link android.support.v4.view.PagerAdapter} that will provide
* fragments for each of the sections. We use a
* {@link FragmentPagerAdapter} derivative, which will keep every
* loaded fragment in memory. If this becomes too memory intensive, it
* may be best to switch to a
* {@link android.support.v4.app.FragmentStatePagerAdapter}.
*/
private SectionsPagerAdapter mSectionsPagerAdapter;

/**
* The {@link ViewPager} that will host the section contents.
*/
private ViewPager mViewPager;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);


setSupportActionBar(toolbar);
// Create the adapter that will return a fragment for each of the
three
// primary sections of the activity.
mSectionsPagerAdapter = new
SectionsPagerAdapter(getSupportFragmentManager());

// Set up the ViewPager with the sections adapter.


mViewPager = (ViewPager) findViewById(R.id.container);
mViewPager.setAdapter(mSectionsPagerAdapter);

TabLayout tabLayout = (TabLayout) findViewById(R.id.tabs);


tabLayout.setupWithViewPager(mViewPager);

@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is
present.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();

//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}

return super.onOptionsItemSelected(item);
}
//deleted PlaceholderFragment class from here
/**
* A {@link FragmentPagerAdapter} that returns a fragment corresponding
to
* one of the sections/tabs/pages.
*/
public class SectionsPagerAdapter extends FragmentPagerAdapter {

public SectionsPagerAdapter(FragmentManager fm) {


super(fm);
}

@Override
public Fragment getItem(int position) {
//Returning the current tab
switch (position) {
case 0:
Tab1spring tab1 = new Tab1spring();
return tab1;
case 1:
Tab2steamingground tab2 = new Tab2steamingground();
return tab2;
case 2:
Tab3fumarole tab3 = new Tab3fumarole();
return tab3;
case 3:
Tab4hotpool tab4 = new Tab4hotpool();
return tab4;
case 4:
Tab5tambahan tab5 = new Tab5tambahan();
return tab5;
case 5:
Tab6info tab6 = new Tab6info();
return tab6;
default:
return null;
}
}

@Override
public int getCount() {
// Show 6 total pages.
return 6;
}

@Override
public CharSequence getPageTitle(int position) {
switch (position) {
case 0:
return "page 1";
case 1:
return "page 2";
case 2:
return "page 3";
case 3:
return "page 4";
case 4:
return "page 5";
case 5:
return "help";
}
return null;
}
}
}

You might also like