hi guys,

i have a application which is a local search.

i'm using a SimpleCursorAdapter for this. search result returns a
searched results, but when displaying it displays all the contacts.

this is my Contact Display class

abstract class ContactList extends ListActivity {
        DisplayCon dispCont;
        Cursor cursor;
        TextView stat;
        String[] columns;
        int[] names;
        abstract SimpleCursorAdapter myAdapter(Intent intent);

        public class DisplayCon extends SimpleCursorAdapter {
                private LayoutInflater mInflater;
                Context mCtx;

                public DisplayCon(Context context, int layout, Cursor c, 
String[]
from,
                                int[] to) {
                        super(context, layout, c, from, to);
                        // TODO Auto-generated constructor stub
                        mInflater = LayoutInflater.from(context);
                        this.mCtx = context;
                }

                @Override
                public void bindView(View view, Context context, Cursor c) {
                        // TODO Auto-generated method stub
                        // TODO Auto-generated method stub
                        // int idCol = c.getColumnIndex(Phones._ID);
                        // try {
                        int nameCol = c.getColumnIndex(Phones.NAME);
                        int numCol = c.getColumnIndex(Phones.NUMBER);
                        int foreign = c.getColumnIndex(Phones.PERSON_ID);
                        String name = c.getString(nameCol);
                        String number = c.getString(numCol);
                        // long id = c.getLong(idCol);
                        long phoneForeign = c.getLong(foreign);
                        // View v = mInflater.inflate(R.layout.contacts, 
parent, false);
                        TextView name_text = (TextView)
view.findViewById(R.id.contactName);
                        if (name_text != null) {
                                name_text.setText(name);
                        }

                        TextView num_text = (TextView) 
view.findViewById(R.id.number);
                        if (num_text != null) {
                                num_text.setText(number);
                        }

                        // set the profile picture
                        ImageView profile = (ImageView) 
view.findViewById(R.id.imgContact);
                        if (profile != null) {
                                // Uri uri = 
ContentUris.withAppendedId(People.CONTENT_URI,
                                // id);
                                Cursor cur = 
getContentResolver().query(Photos.CONTENT_URI,
                                                null, Photos.PERSON_ID + "='" + 
phoneForeign + "'",
                                                null, null);
                                byte[] b = null;
                                if (cur != null) {
                                        if (cur.moveToNext()) {
                                                int imgColumn = 
cur.getColumnIndex(Photos.DATA);
                                                b = cur.getBlob(imgColumn);
                                        }
                                }
                                Bitmap bm = null;
                                if (b != null) {
                                        ByteArrayInputStream bytes = new 
ByteArrayInputStream(b);
                                        BitmapDrawable bmd = new 
BitmapDrawable(bytes);
                                        bm = bmd.getBitmap();
                                        profile.setImageBitmap(bm);
                                } else {
                                        
profile.setImageResource(R.drawable.defaultcontact);
                                }
                        }
                }

                @Override
                public Object getItem(int position) {
                        // TODO Auto-generated method stub
                        return super.getItem(position);
                }

        }

        @Override
        protected void onCreate(Bundle savedInstanceState) {
                // TODO Auto-generated method stub
                super.onCreate(savedInstanceState);
                cursor = getContentResolver().query(Phones.CONTENT_URI, null,
                                null, null, Phones.NAME + " ASC");
                startManagingCursor(cursor);
                columns = new String[] { Phones.NAME, Phones.NUMBER };
                names = new int[] { R.id.contactName, R.id.number };
                //dispCont = new DisplayCon
                dispCont = new DisplayCon(this, R.layout.contacts, cursor,
                                columns, names);
                setDefaultKeyMode(DEFAULT_KEYS_SEARCH_LOCAL);
                onNewIntent(getIntent());
                setListAdapter(dispCont);
                // setListAdapter(new DisplayContacts(this));
                registerForContextMenu(getListView());
        }

        @Override
        protected void onNewIntent(Intent intent) {
                // TODO Auto-generated method stub
                SimpleCursorAdapter adapter = myAdapter(intent);
                if (adapter == null) {
                        finish();
                } else {
                        setListAdapter(adapter);
                }
        }
}

this is my search class

public class Result extends ContactList {

        @Override
        SimpleCursorAdapter myAdapter(Intent intent) {
                // TODO Auto-generated method stub
                SimpleCursorAdapter adapter = null;
                if (intent.getAction().equals(Intent.ACTION_SEARCH)) {
                        String query = 
intent.getStringExtra(SearchManager.QUERY);
                        cursor = searchItems(query);
                        Log.d("CURSOR_LENGHT", 
Integer.toString(cursor.getCount()));
                        adapter = new SimpleCursorAdapter(this, R.layout.main, 
cursor,
columns, names);
                }
                return (adapter);
        }

        private Cursor searchItems(String query) {
                Cursor cur = getContentResolver().query(People.CONTENT_URI, 
null,
                                People.NAME + "='" + query + "'", null, null);
                startManagingCursor(cur);
                int x = cur.getCount();
                if (cur == null || x == 0) {
                        // alert("Address Book", "Empty Address Book");
                }
                if (cur.moveToNext()) {
                        do {
                                Log.d("CURSOR_SSSS", Integer.toString(x));
                        } while (cur.moveToNext());
                }
                columns = new String[] { People.NAME, People.NUMBER };
                names = new int[] { R.id.contactName, R.id.number };
                //dispCont = new DisplayCon
                /*dispCont = new DisplayCon(this, R.layout.contacts, cursor,
                                columns, names);        */
                return cur;
        }

}

this reruns a result but when it redirects to previous class displays
all

this is my

public class search extends ContactList {
        /** Called when the activity is first created. */

        @Override
        SimpleCursorAdapter myAdapter(Intent intent) {
                // TODO Auto-generated method stub
                return (new
SimpleCursorAdapter(this,R.layout.main,cursor,columns,names));
        }
}

and this is my androidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android";
      package="com.test"
      android:versionCode="1"
      android:versionName="1.0">
    <application android:icon="@drawable/icon" android:label="@string/
app_name" android:debuggable="true">
        <activity android:name=".search"
                  android:label="@string/app_name">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category
android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
            <meta-data android:name="android.app.default_searchable"
                                                 android:value=".Result" />
        </activity>

       <activity android:name=".Result"
                        android:label="Result"
                        android:launchMode="singleTop">
                        <intent-filter>
                                <action 
android:name="android.intent.action.SEARCH" />
                                <category 
android:name="android.intent.category.DEFAULT" />
                        </intent-filter>
                        <meta-data android:name="android.app.searchable"
android:resource="@xml/searchable" />
                </activity>

    </application>
    <uses-sdk android:minSdkVersion="4" />

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

this is my searchable.xml

<searchable xmlns:android="http://schemas.android.com/apk/res/android";
                 android:label="@string/search_label"
                 android:hint="@string/search_hint" />


need some help

regards,
Mike

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