living_sword
03-23-2008, 11:52 PM
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 (http://www.modmygphone.com/wiki/index.php/Using_Search_API).
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.
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"};- mImageNames is used to give 'names' to the drawables and will be used to compare with the user-query.
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,
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]);
}
}
}
Thats it. With this, you can use the Search API to look for stuff inside /res/ folder.
Updated Source (http://www.modmygphone.com/forums/downloads.php?do=file&id=21).
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.
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"};- mImageNames is used to give 'names' to the drawables and will be used to compare with the user-query.
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,
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]);
}
}
}
Thats it. With this, you can use the Search API to look for stuff inside /res/ folder.
Updated Source (http://www.modmygphone.com/forums/downloads.php?do=file&id=21).