This seems to be a pretty common problem the beginners face. Despite
reading all the solutions, I could not arrive at a solution. Please
point out the mistake I am doing.

Main Activity:

package com.nitinsethi.smsfinder;

import java.util.ArrayList;

import android.app.ListActivity;
import android.content.Intent;
import android.database.Cursor;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;

public class SMSFinderActivity extends ListActivity {


        private Cursor mSmsCursor;
        public static final String KEY_SENDER = "person";
        public static final String KEY_BODY = "body";

        private ArrayList<String> msgs = new ArrayList<String>();

        /** Called when the activity is first created. */
        @Override
        public void onCreate(Bundle savedInstanceState) {
                super.onCreate(savedInstanceState);
                setContentView(R.layout.main);
        }

        public void findSMS(View search) {
                Uri uri = Uri.parse("content://sms/inbox");
                String wordToFind = ((EditText)
findViewById(R.id.wordToFind)).getText().toString();
                mSmsCursor = getContentResolver().query(uri,new String[]
{ KEY_SENDER, KEY_BODY },KEY_BODY + " LIKE " + "\"%" + wordToFind + "%
\"", null,"date" + " DESC");
                startManagingCursor(mSmsCursor);

                if ( mSmsCursor.moveToFirst()) {
                        do{
        
msgs.add(mSmsCursor.getString(mSmsCursor.getColumnIndexOrThrow(KEY_BODY)));
                        } while(mSmsCursor.moveToNext());
                }

                Intent intent = new Intent(this, ShowSMSListActivity.class);

                Bundle arrayBundled = new Bundle();
                arrayBundled.putStringArrayList("smslist", msgs);
                intent.putExtras(arrayBundled);
                startActivity(intent);
        }

}


SMSList Activity


package com.nitinsethi.smsfinder;

import java.util.ArrayList;

import android.app.ListActivity;
import android.os.Bundle;
import android.util.Log;
import android.widget.ArrayAdapter;

public class ShowSMSListActivity extends ListActivity {

        public void onCreate(Bundle savedInstanceState) {

                super.onCreate(savedInstanceState);

                setContentView(R.layout.sms_list);


                Bundle bundle = getIntent().getExtras();
                ArrayList<String> msgs = bundle.getStringArrayList("smslist");

                Log.d("ShowSMSListActivity",msgs.get(1));

                ArrayAdapter<String> arrayAdapter = new 
ArrayAdapter<String>(this,
R.layout.listitem_layout,msgs);
                setListAdapter(arrayAdapter);

        }
}


main.xml:


<?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" >

    <EditText
        android:id="@+id/wordToFind"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:hint="Type the word to find.."
        android:padding="10dip" />

    <Button
        android:id="@+id/search"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="right"
        android:padding="10dip"
        android:text="Search SMS"
        android:onClick="findSMS" />

</LinearLayout>


sms_list.xml:


<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/
android"
      android:layout_width="wrap_content"
        android:layout_height="wrap_content">

    <ListView android:id="@+id/android:list"
          android:layout_width="wrap_content"
                android:layout_height="wrap_content"/>


        <TextView android:id="@+id/android:empty"
          android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="No SMS"/>
</LinearLayout>


listitem_layout.xml


<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android";
    android:id="@+id/text1"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:paddingRight="100dip"
    android:textSize="30dip" />




-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to