Wednesday, 23 November 2011

ListView Multiple Choice

main.xml



<?xml version="1.0" encoding="utf-8"?>
<LinearLayout android:id="@+id/Layout1"
android:layout_width="fill_parent" android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android">
<ListView android:id="@+id/ListView1" android:layout_height="wrap_content"
android:layout_width="fill_parent"></ListView>
</LinearLayout>


ListViewMultipleChoice.java


 public class ListViewMultipleChoice extends Activity {
private ListView list;
private String lv_items[] = { "Android", "iPhone", "BlackBerry"};

@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);

setContentView(R.layout.main);

list = (ListView) findViewById(R.id.ListView1);

list.setAdapter(new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_multiple_choice, lv_items));
list.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
}
}







Tuesday, 22 November 2011

Progress Dialog


import android.app.Activity;
import android.app.ProgressDialog;
import android.content.pm.ActivityInfo;
import android.os.Bundle;

public class ProgressDialogActivity extends Activity {
    /** Called when the activity is first created. */
    ProgressDialog pro;
    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_USER);
        setContentView(R.layout.main);
         pro=new ProgressDialog(this);
         pro.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
         pro.setMax(300);
         pro.setCancelable(true);
         pro.setMessage("Loading data..");
         pro.show();
         Threadex t=new Threadex();
         t.start(); //start thread
   // t.stomth();
    }//This is Oncreate method
    class Threadex extends Thread
    {
        public void stomth()
        {
            pro.dismiss();
        }
        public void run()
        {
            for(int i=10;i<=pro.getMax();i=i+10)
            {
                pro.incrementProgressBy(10);
                try
                {
                sleep(1000); //sleep for 1 seconds
                }
                catch(Exception e)
                {
                e.printStackTrace();
                }
           
            } //this is for loop ends
           
            pro.dismiss();
           
           
        } //this is end of Run
    }//This is End of Threadex
} //This is End of Activity

Here Update the 10 distance continues Upto 300 distance because we have set 300 distance as max .



This is after the Dismiss the ProgressDialog




This is for ProgressDialog.STYLE_HORIZONTAL.
we can set Another Style ProgressDialog.STYLE_SPINNER but view is different

Monday, 14 November 2011

Getting SMS in your Activity

import android.app.Activity;
import android.database.Cursor;
import android.net.Uri;
import android.os.Bundle;
import android.widget.TextView;

public class SMSActivity extends Activity
{
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
TextView textview = new TextView(this);
Uri url = Uri.parse("content://sms/inbox");
Cursor cursor = getContentResolver().query(url, null, null, null,null);
String smsdisplay = "";
while (cursor.moveToNext()) {
smsdisplay += "From :" + cursor.getString(2) + " : " + cursor.getString(11)+"\n";
}
textview.setText(smsdisplay);
setContentView(textview);
}
}

in the AndroidManifest.xml

"<uses-permission android:name="android.permission.READ_SMS"/>"

Gives this Permission for Reading SMS in your activity.