Posts

Showing posts from September, 2013

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 + zipname)…

Custom DialogFragment Example in android

Image
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(Window.FEA…

Simple TextToSpeech Example in Android

Image
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.setOnClickListener…

Spinner with multiple selection in Android

Image
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 selected indexes as a list of integers

I hope this post is usef…