Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Android json query result from sql table

Options
  • 23-12-2015 9:19pm
    #1
    Registered Users Posts: 1,550 ✭✭✭


    I'm just learning Android and I'm using volley and JsonObjectRequest.
    I'm having a bit of trouble with it to be honest.
    I'm working on a project for practice.
    I have a table with a userid that is associated with a number of transactions in a table.
    I would like to press a button View recent transactions and have another activity window pop up with all the transactions belonging to the user.
    So the kind of query I would want to execute would be.
    select date,transaction_id, name_of_item from transactions where transactions.userid = userid.
    The value I want to send over is the userid.

    I'm not sure how to send the userid over on one activity and have the results pop up on another.
    Please help if you can.


Comments

  • Registered Users Posts: 1,550 ✭✭✭quinnd6


    Well I found out I could get it all to work on one activity.
    I got close to getting it to work using StringRequest from the volley package.
    Unfortunately the string given back was in Json format so didn't look too good.
    Anytime I use JsonObjectRequest it doesn't work at all.
    Hopefully ye understand what I'm trying to do ie. send the userid over to the database and get the transaction data back.


  • Registered Users Posts: 1,550 ✭✭✭quinnd6


    This is brutal I'm just talking to myself here.
    I got it working but it still looks bad because I'm just using a TextView and printing Strings into it with no formatting.
    I need to figure out how to put the Strings into a proper table using Android Studio.
    That's another days work anyway.
    If anyone has any help on putting Strings obtained from a JsonObject into a table in Android I'd be happy to see it.


  • Registered Users Posts: 1,547 ✭✭✭rock22


    i can help with JSON , I know nothing of Javascript.
    However in Android i wonder if you have looked at ListView and adapter to control layout. This should be easier that using TextView to get an acceptable table.


  • Registered Users Posts: 1,550 ✭✭✭quinnd6


    ListView is just one column going down though isn't it.
    I think it would look better and be more readable with multiple columns for what I'm doing.


  • Registered Users Posts: 1,547 ✭✭✭rock22




  • Advertisement
  • Registered Users Posts: 1,550 ✭✭✭quinnd6


    Thanks for that I'm going to give that a try when Christmas is over.
    Happy Christmas rock22.


  • Registered Users Posts: 1,550 ✭✭✭quinnd6


    That tutorial link did help thanks.
    I used it with some other resources and managed to get the data into columns.
    The tricky part now seems to be adding column headers eg, date, description on top of each column of data.
    Is there an easy way of adding them to a ListView?


  • Registered Users Posts: 18,272 ✭✭✭✭Atomic Pineapple


    Not sure how you've created the columns but here is how to add section headers to a ListView - http://javatechig.com/android/listview-with-section-header-in-android


  • Registered Users Posts: 1,550 ✭✭✭quinnd6


    I'm afraid that last link wasn't what I was looking for.
    I found another tutorial that uses tablelayout with textviews inside in a listview on youtube.
    The problem is it needs to work for 3 columns and while the first 2 align ok with the headers the last column doesn't align properly with the 3rd header.

    It's ok I went back to using linearlayout and weights and got it all lined up properly now.


Advertisement