- 03-23-2008, 10:52 PM #1
Searching for images in 'drawable' folder
There would be some occasions when you would want to search images in the '/res/drawable' folder. Some small changes need to be made to the tutorial here.
1. We won't be doing any database activities, so all references to it can be removed/commented.
2. Define two arrays, an Integer mImageIds and a String mImageNames inside Image class.
- mImageNames is used to give 'names' to the drawables and will be used to compare with the user-query.Code:public static Integer[] mImageIds= { R.drawable.nevada, R.drawable.pooh, R.drawable.sunflower, R.drawable.the_maldives, R.drawable.sky **; public static String[] mImageNames = {"nevada", "pooh","sunflower", "the_maldives", "sky"**;
3. Replace all occurences of mUrls in ImageAdapter class with mImageIds.
4. In ImageSearch.java, change the result ArrayList to Integer type.
5. In ImageAdapter class, replace,
i.setImageURI(mUris[position]);
with,
i.setImageResource(result.get(position));
and all references of mUris with result.
6. The doSearchQuery() method becomes very simple,
Thats it. With this, you can use the Search API to look for stuff inside /res/ folder.Code:private void doSearchQuery(final Intent queryIntent, final String entryPoint) { result = new ArrayList<Integer>(); queryString = queryIntent.getStringExtra(SearchManager.QUERY); setTitle("Search results for "+"'"+queryString+"'"); for (int i = 0; i < Images.mImageNames.length; i++) { if(Images.mImageNames[i].contains(queryString)) { result.add(Images.mImageIds[i]); ** ** **
Updated Source.


LinkBack URL
About LinkBacks
Reply With Quote