0

I have a spinner widget and I want to populate some data when user clicks on one of the items from spinner. So I have the position number like 0,1,2,3... for spinner items.

Now I have a table which have three fields as

  _id    cid    relatedname

   1       1          A
   2       1          B
   3       2          C
   4       2          D
   5       2          E

I want when a user clicks position 1 from spinner then it will check for cid and all the relatedname will be displayed whose cid is 1.

How to do this ?

2
  • 1
    what is your problem? querying the table or knowing when the selected element has changed? Commented Nov 29, 2011 at 9:47
  • how can i relate position and cid .how to iterate through cid and get realtedname. Commented Nov 29, 2011 at 9:50

2 Answers 2

2

setOnItemChangelistener() to spinner then do as follows in tat listener.

loadRelatedName(position + 1);    

void loadRelatedName(int cid) 
{
     sql = " SELECT * FROM table WHERE cid = " + cid;
     Cursor c = db.select(sql);
     if (c ! null)
        while(c.moveToNext()) {
            Syso("Related Name : " + c.getString[2]);
     }
}
Sign up to request clarification or add additional context in comments.

Comments

0

Add a OnItemSelectedListener to the spinner to get the selected item.

See this

There you can get the position. With that you can query your database. Probably something like:

SELECT relatedname from mytable where cid=<selectedpos>

This will get you all entries where cid has the same value as the selected position. Note: It may be that the indexes of the spinner are zero based and cid is not. So maybe you need to add 1 to the selected position before querying the table

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.