Skip to main content

Posts

Showing posts from September, 2013

Featured post

Simple RecyclerView example with filter option in Android

Hi Guys, Maybe you all are expert in terms of using RecyclerView in android. This blog is simple example for using filter option with RecyclerView adapter. As for now you will instantiate RecyclerView and set the adapter to RecyclerView as following way. RecyclerView list = (RecyclerView) findViewById(R.id.list); list.setLayoutManager(new LinearLayoutManager(this)); list.setHasFixedSize(true); ArrayList&ltNumber&gt numbers = new ArrayList&lt&gt(); String ONEs[] = {"ZERO", "ONE", "TWO", "THREE", "FOUR", "FIVE", "SIX", "SEVEN", "EIGHT", "NINE", "TEN"}; String TENs[] = {"ZERO", "TEN", "TWENTY", "THIRTY", "FOURTY", "FIFTY", "SIXTY", "SEVENTY", "EIGHTY", "NINETY", "HUNDRED"}; String HUNDREDS[] = {"ZERO", "HUNDRED", "TWO HUND

Simple Example for extracting zip file in android

You can extract zip file by using ZipInputStream class in android. MainActivity.java package com.android.zipextracter; import java.io.BufferedInputStream; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.util.zip.ZipEntry; import java.util.zip.ZipInputStream; import android.os.Bundle; import android.os.Environment; import android.widget.Toast; import android.app.Activity; public class MainActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); String zipFilePath = Environment.getExternalStorageDirectory() .getAbsolutePath()+"/"; unpackZip(zipFilePath, "MyRar.zip"); } private boolean unpackZip(String path, String zipname) { InputStream is; ZipInputStream zis; try { String filename; is = new FileInputStream(path + zipn

Custom DialogFragment Example in android

By this example you can access your DialogFragment throughout the application. You can send arguments to DialogFragment, and also you can retrieve values from DialogFragment. Screenshot: Code: MyCustomDialog.java package com.andoid.dialogfragment; import android.app.Dialog; import android.app.DialogFragment; import android.graphics.Color; import android.graphics.drawable.ColorDrawable; import android.os.Bundle; import android.view.View; import android.view.View.OnClickListener; import android.view.Window; import android.view.WindowManager; import android.widget.Button; import android.widget.EditText; public class MyCustomDialog extends DialogFragment { Button mButton; EditText mEditText; onSubmitListener mListener; String text = ""; interface onSubmitListener { void setOnSubmitListener(String arg); } @Override public Dialog onCreateDialog(Bundle savedInstanceState) { final Dialog dialog = new Dialog(getActivity()); dialog.getWindow().requestFeature(Wi

Simple TextToSpeech Example in Android

Now possible to hear the spoken of words by Android. Screenshot: Code: TextToSpeechActivity.java package com.android.texttospeach; import android.app.Activity; import android.os.Bundle; import android.speech.tts.TextToSpeech; import android.util.Log; import android.view.View; import android.widget.Button; import android.widget.EditText; import java.util.Locale; public class TextToSpeechActivity extends Activity implements TextToSpeech.OnInitListener { private static final String TAG = "MyTextToSpeechDemo"; private TextToSpeech mTts; private Button mPlayButton; EditText mEditText; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.text_to_speech); // Initialize text-to-speech. This is an asynchronous operation. mTts = new TextToSpeech(this, this); mPlayButton = (Button) findViewById(R.id.button1); mEditText = (EditText) findViewById(R.id.editText1); mPlayButton.setOnClickL

Spinner with multiple selection in Android

Video Output: Source code link is added below. Here we have a class called MultiSelectionSpinner . In this class we have following methods. public void setItems(String[] items) Used to set adapter items using array of strings to this spinner. public void setItems(List items) Used to set adapter items using list of strings to this spinner. public void setSelection(String[] selection) Used to set selected items on this adapter using array of strings to this spinner. public void setSelection(List selection) Used to set selected items on this adapter using list of strings to this spinner. public void setSelection(int index) Used to set single selected item using position to this spinner. public void setSelection(int[] selectedIndices) Used to set selected items using array of integers to this spinner. public List getSelectedStrings() Used to get the selected items as a string public List getSelectedIndices() Used to get the se