Making A Sample App using Android Studio
package xyz.himeshjain.thequotes;
import android.content.Intent;import android.media.MediaPlayer;import android.support.v7.app.AppCompatActivity;import android.os.Bundle;import android.view.View;import android.widget.CompoundButton;import android.widget.RelativeLayout;import android.widget.Switch;import android.widget.TextView;
import java.util.ArrayList;
public class Quotes extends AppCompatActivity {
MediaPlayer namokar1; Switch namo;
int count=0; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_quotes); namokar1 = MediaPlayer.create(this, R.raw.namokar); namo = (Switch) findViewById(R.id.switch1); namo.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { if(isChecked){ namokar1.seekTo(0); namokar1.start(); namokar1.setLooping(true); } else { namokar1.reset(); Intent intent = getIntent(); finish(); }
}
}); RelativeLayout touch = (RelativeLayout) findViewById(R.id.touch); final TextView quoteText = (TextView) findViewById(R.id.quote); final TextView personText = (TextView) findViewById(R.id.person); final ArrayList<Quote> quoteList = new ArrayList<>();
Quote quote1= new Quote("Random Quotes", "Random People"); quoteList.add(quote1);
Quote quote2 = new Quote("Only 2 things are infinite in the world, Human Stupidity and Universe and I am not sure about the latter", "Albert Einstein"); quoteList.add(quote2);
Quote quote3 = new Quote("I was gonna be the first person in my family to graduate from community college. Everyone else graduated from normal college", "Troy Barnes"); quoteList.add(quote3);
//Add more quotes here touch.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (count < quoteList.size()) {
Quote q = quoteList.get(count); quoteText.setText(q.getQuote()); personText.setText(q.getPerson()); count = count + 1; } else{
count = 0; }
}
}); }
}
Comments
Post a Comment