0

I have implemented the search bar in my app and it´s working fine, but at the moment I also want to show an icon at the right side of a custom suggestion.

developer.android.com says that I have to add a Column "SUGGEST_COLUMN_ICON_2" with a reference to the images.

The Problem is that I don´t know how to add this to my cursor because this can´t be done by sql.

The images I want to set depends on which value a certain column (status) of my curser has got.

String sql="SELECT U._id, U.name AS suggest_text_1, C.status FROM table1 AS U LEFT OUTER JOIN table2 AS C ON U.number=C.number WHERE suggest_text_1 LIKE \"%"+selectionArgs[0]+"%\" ORDER BY suggest_text_1 ASC"

The images I want to use are in the drawable folder.

table1 has got: _id, name, number

table 2 has got: _id, number, status, ....

Sergey Benner
  • 4,421
  • 2
  • 22
  • 29
anonymous
  • 1,141
  • 3
  • 11
  • 20
  • Create a table with a list of your images in the drawable folder then reference the table with drawables with a foreign key like table - status_id,drawable --- then reference the status_id from another table and this will get you your drawable. – Sergey Benner Jan 18 '12 at 19:01

1 Answers1

0

OK. In your case your table2 will have number,status,drawable fields. the drawable field will have your images that should do your trick. even you can omit the number field and join on the status_id right away.

example:

table1 id int ,name varchar(?),table2_id int fk references table2(id) --
table2 id int pk,status varchar(?),status_drawable_id int fk references drawables_table (id)  
drawables_table id int pk ,drawables varchar(?) --

select t1.id,t1.name,t2.status,dt.drawable from table1 t1
inner join table2 t2
on t1.status_id=t2.id
inner join drawables_table dt
on t2.status_drawable_id=dt.id
where t1.name like '% blech %'
order by t1.name
Sergey Benner
  • 4,421
  • 2
  • 22
  • 29
  • Sounds like a good idea. unfortunately I would have to create a third table with status and drawable. The remaining question is now, how i can create the sql statement so that the result has got id and name from table1 and drawable from table3. Because table2 is still needed for getting the right statement it isquite confusing creating the sql statement. – anonymous Jan 18 '12 at 19:39
  • why would you need a 3rd table? you can add a field with drawable to your 2nd table? and retrieve with a join just using the foreign key. you should post your create table statements perhaps. – Sergey Benner Jan 18 '12 at 19:42
  • Because my table2 has a lot of rows and there are only 4 different status. Saving the drawable additionally to the status in table2 would create an unneccessary data overhead. Also i would have to change 2 data fields if the status would change. The third table i would never have to edit agein. – anonymous Jan 18 '12 at 19:46
  • hm I will have to try this tomorrow. – anonymous Jan 18 '12 at 19:58
  • and here's an article (one of many) about how find a view by string id http://stackoverflow.com/questions/7015907/is-possible-in-android-to-findview-by-string-id – Sergey Benner Jan 18 '12 at 20:04
  • Is it also possible without changing table1 and table2 and only add table 3 with the mentioned columns? – anonymous Jan 21 '12 at 00:40
  • you can do it but if the status is varchar i would recommend making it a number and move it into a separate table with your drawables if not then you will have to join using this status and a status in the new table – Sergey Benner Jan 21 '12 at 10:51