samedi 17 octobre 2015

Get SQLite table ID when row is clicked

How to find out the table ID in SQLite when the row is clicked? I have two tables, one is Info and another is WorkForce. I have implemented a tableListener in DisplayData.java. Everytime the row is pressed, it will retrieved all the information based on the name and ID by using this query

c = database.rawQuery("SELECT w.Subcontractors, w.NumberOfPerson, w.NumberOfHours FROM" +
        "Information i LEFT JOIN WorkForce w ON w.TInfo_id = i.ID WHERE i.Name = ? AND i.ID= ? ",
        new String[]
        {
            String.valueOf(name2),String.valueOf(date2)
        }
        , null);

Table Info

ID          Name        Weather        Date     Status    
----------  ----------  ----------  ----------  ----------
   1           Paul       Sunny       15/10      MC
   2           Allen      Rainy       15/10      Working

Table WorkForce

ID        Subcontractors   NumberOfPeople      NumberOfHours   TInfo_id
----------  --------------   ----------       ----------       -------
    1           AAA               2                2              1
    2           BBB               3                1              2

Assuming there are two row in DisplayData.java, which are the two row in Table Info. If the first row is pressed, it will retrieved all the information from table Info and Table WorkForce...

DisplayData.java

row.setOnClickListener(new View.OnClickListener() {    
    public void onClick(View v) {
        Intent intent = new Intent(DisplayData.this, UpdatePage.class);
        intent.putExtra("name", name);
        // code for finding id in tableInfo
        startActivity(intent);
   }
});

Does setOnItemClickListener works in tableLayout? If not, what are the method I can use to achieve this? Thanks

Aucun commentaire:

Enregistrer un commentaire