Você está na página 1de 9

MainActivity.

java
package net.golanug.johan.viewpager;
import android.media.MediaPlayer;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.ViewFlipper;
import android.view.MenuItem;
public class MainActivity extends Activity {
ViewFlipper viewFlipper;
Button next,previous;
MediaPlayer audioBackground;
MediaPlayer audioNext;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
audioNext= MediaPlayer.create(this, R.raw.klik);
//Memanggil file my_sound pada folder raw
/* audioBackground = MediaPlayer.create(this, R.raw.saihorasma);
//Set looping ke true untuk mengulang audio jika telah selesai
audioBackground.setLooping(true);
//Set volume audio agar berbunyi
audioBackground.setVolume(1,1);
//Memulai audio
audioBackground.start();

*/
viewFlipper=(ViewFlipper)findViewById(R.id.ViewFlipper01);
next=(Button)findViewById(R.id.Next);
previous=(Button)findViewById(R.id.Previous);
next.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//Set looping ke true untuk mengulang audio jika telah selesai
audioNext.start();
audioNext.setVolume(1,1);
viewFlipper.showNext();
viewFlipper.setFlipInterval(3000);
}
});
//batas next
previous.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
viewFlipper.showPrevious();
audioNext.start();
audioNext.setVolume(1,1);
viewFlipper.setFlipInterval(3000);
}
});
}
@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);
}
}
=============================================================
=======
activity_main.xml
<?xml version=1.0 encoding=utf-8?>
<LinearLayout
xmlns:android=http://schemas.android.com/apk/res/android&#8221;
android:id=@+id/LinearLayout01
android:layout_width=fill_parent
android:layout_height=fill_parent
android:orientation=vertical >
<RelativeLayout
android:id=@+id/RelativeLayout02
android:layout_width=wrap_content
android:layout_height=wrap_content>
<ViewFlipper
android:id=@+id/ViewFlipper01

android:layout_width=fill_parent
android:layout_height=350dp >
<RelativeLayout
android:layout_width=fill_parent
android:layout_height=match_parent
android:layout_gravity=center_horizontal
android:background=@drawable/ulos_ragi_hotang >
<TextView
android:layout_width=wrap_content
android:layout_height=wrap_content
android:textColor=#adccee
android:textSize=20pt
android:layout_centerHorizontal=true
android:layout_marginTop=200dp
android:text= RAGI HOTANG >
</TextView>
</RelativeLayout>
<RelativeLayout
android:layout_width=match_parent
android:layout_height=match_parent
android:background=@drawable/ulos_ragi_hotang
android:orientation=vertical >
<TextView
android:layout_width=wrap_content
android:layout_height=wrap_content
android:textColor=#adccee
android:textSize=20pt
android:layout_centerHorizontal=true
android:layout_marginTop=200dp
android:text= RAGI HOTANG >
</TextView>
</RelativeLayout>

<RelativeLayout
android:layout_width=match_parent
android:layout_height=match_parent
android:background=@drawable/ulos_antuk_antuk
android:textSize=10pt
android:orientation=vertical >
<TextView
android:layout_width=wrap_content
android:layout_height=wrap_content
android:textColor=#FFFFFF
android:textSize=20dp
android:layout_centerHorizontal=true
android:layout_marginTop=100dp
android:text=ULOS ANTUK ANTUK >
</TextView>
</RelativeLayout>
<RelativeLayout
android:layout_width=match_parent
android:layout_height=match_parent
android:background=@drawable/ulos_bintang_maratur
android:textSize=10pt
android:orientation=vertical >
<TextView
android:layout_width=wrap_content
android:layout_height=wrap_content
android:textColor=#ffffff
android:textSize=20dp
android:layout_centerHorizontal=true
android:layout_marginTop=100dp
android:text=ULOS BINTANG MARATUR >
</TextView>

</RelativeLayout>
<RelativeLayout
android:layout_width=match_parent
android:layout_height=match_parent
android:background=@drawable/ulos_bolean
android:textSize=10pt
android:orientation=vertical >
<TextView
android:layout_width=wrap_content
android:layout_height=wrap_content
android:textColor=#ffffff
android:textSize=20dp
android:layout_centerHorizontal=true
android:layout_marginTop=100dp
android:text=ULOS BOLEAN >
</TextView>
</RelativeLayout>
<RelativeLayout
android:layout_width=match_parent
android:layout_height=match_parent
android:background=@drawable/ulos_mangiring
android:textSize=10pt
android:orientation=vertical >
<TextView
android:id=@+id/TextView04
android:layout_width=wrap_content
android:layout_height=wrap_content
android:textColor=#ffffff
android:textSize=20dp
android:layout_centerHorizontal=true
android:layout_marginTop=100dp
android:text=ULOS MANGIRING >

</TextView>
</RelativeLayout>
<RelativeLayout
android:layout_width=match_parent
android:layout_height=match_parent
android:textSize=10pt
android:background=@drawable/ulos_padang_ursa
android:orientation=vertical >
<TextView
android:id=@+id/TextView04
android:layout_width=wrap_content
android:layout_height=wrap_content
android:textColor=#ffffff
android:textSize=20dp
android:layout_centerHorizontal=true
android:layout_marginTop=100dp
android:text=ULOS PADANG URSA >
</TextView>
</RelativeLayout>
<RelativeLayout
android:layout_width=match_parent
android:layout_height=match_parent
android:textSize=10pt
android:background=@drawable/ulos_pinuncaan
android:orientation=vertical >
<TextView
android:id=@+id/TextView04
android:layout_width=wrap_content
android:layout_height=wrap_content
android:textColor=#ffffff
android:textSize=20dp
android:layout_centerHorizontal=true
android:layout_marginTop=100dp
android:text=ULOS PINUNCAAN >

</TextView>
</RelativeLayout>
<RelativeLayout
android:layout_width=match_parent
android:layout_height=match_parent
android:background=@drawable/ulos_ragi_huting
android:textSize=10pt
android:orientation=vertical >
<TextView
android:id=@+id/TextView04
android:layout_width=wrap_content
android:layout_height=wrap_content
android:textColor=#ffffff
android:textSize=20dp
android:layout_centerHorizontal=true
android:layout_marginTop=100dp
android:text=ULOS RAGI HUTING >
</TextView>
</RelativeLayout>
</ViewFlipper>
</RelativeLayout>
<RelativeLayout
android:id=@+id/RelativeLayout03
android:layout_below=@+id/RelativeLayout02
android:background=#000000
android:layout_width=fill_parent
android:layout_height=match_parent>
<Button
android:id=@+id/Previous
android:textColor=#123a1a
android:textSize=12pt
android:layout_marginLeft=20dp
android:layout_width=match_parent

android:layout_height=wrap_content
android:text=Previous
android:backgroundTint=#ff6694ff
android:background=#ff4b33ff
android:layout_centerVertical=true
android:layout_centerHorizontal=true>
</Button>
<Button
android:id=@+id/Next
android:textColor=#123a1a
android:textSize=12pt
android:background=#ff4faa00
android:layout_marginRight=20dp
android:layout_width=match_parent
android:layout_height=wrap_content
android:text=Next
android:backgroundTint=#ffff27
android:layout_alignParentBottom=true
android:layout_centerHorizontal=true>
</Button>
</RelativeLayout>
</LinearLayout>

Você também pode gostar