Skip to content

Instantly share code, notes, and snippets.

@ageorg
ageorg / AlertDialogFragment.java
Created December 18, 2016 22:07
code for AlertDialogFragment
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.os.Bundle;
import android.support.v4.app.DialogFragment;
import android.support.v4.app.Fragment;
import android.support.v7.app.AlertDialog;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
@ageorg
ageorg / fragment_alert_dialog.xml
Created December 18, 2016 22:04
layout for Alert Dialog Fragment
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="example.allilepidrasi.example.AlertDialogFragment">
<!-- TODO: Update blank fragment layout -->
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
@ageorg
ageorg / getIntentWithExtra.java
Created December 18, 2016 21:48
receive intent with extra info
Intent i = getIntent();
Bundle b = i.getExtras();
String name = (String)b.get(MainActivity.TAG_NAME);
TextView nameTextView = (TextView)findViewById(R.id.textView);
nameTextView.setText("Hello " + name);
@ageorg
ageorg / intentWithInfo.java
Created December 18, 2016 21:38
creating an Intent with extra information
nameEditText = (EditText) findViewById(R.id.editText);
Button nextBtn = (Button) findViewById(R.id.btn_next);
nextBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent i = new Intent(MainActivity.this, Main2Activity.class);
String nameStr = nameEditText.getText().toString();
i.putExtra(TAG_NAME, nameStr);
startActivity(i);
@ageorg
ageorg / customDialog2.java
Created December 18, 2016 21:35
custom dialog with auto close operation and sound effect
Button customDialogBtn2 = (Button)findViewById(R.id.btn_custom_2);
customDialogBtn2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
final Dialog dialog = new Dialog(MainActivity.this);
dialog.setContentView(R.layout.custom_dialog2);
dialog.setTitle("My custom dialog");
//set the custom dialog components - text, image and button
TextView text = (TextView) dialog.findViewById(R.id.textView);
@ageorg
ageorg / custom_dialog2.xml
Created December 18, 2016 21:29
custom dialog 2 UI
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<ImageView
android:id="@+id/image"
android:layout_width="wrap_content"
@ageorg
ageorg / customDialog.java
Created December 18, 2016 21:24
show custom dialog with button
Button customDialogBtn = (Button)findViewById(R.id.btn_custom);
customDialogBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
final Dialog dialog = new Dialog(MainActivity.this);
dialog.setContentView(R.layout.custom_dialog);
dialog.setTitle("My custom dialog");
//set the custom dialog components - text, image and button
TextView text = (TextView) dialog.findViewById(R.id.textView);
@ageorg
ageorg / progressbar.java
Created December 14, 2016 21:52
Code for handling progress bar events
tv = (TextView) findViewById(R.id.textView);
tv.setText("2years");
final SeekBar volumeControl = (SeekBar) findViewById(R.id.sb);
volumeControl.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
int progressChanged = 0;
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser){
progressChanged = progress+2;
if (tv!=null) {
@ageorg
ageorg / progressbar.xml
Created December 14, 2016 21:49
progress bar with 4 discrete steps
<SeekBar
android:id="@+id/sb"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:max="3"
android:progress="0"
android:theme="@style/Widget.AppCompat.SeekBar.Discrete" />
@ageorg
ageorg / FlagQuiz_activity_settings.xml
Created November 29, 2016 17:02
activity_settings.xml for FlagQuiz app
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_height="match_parent">
<fragment
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:name="example.allilepidrasi.flagquiz5.SettingsFragment"
android:id="@+id/fragment1"
class="example.allilepidrasi.flagquiz5.SettingsFragment" />