How to make a table to display records from a SQLite database?









up vote
0
down vote

favorite












I got a simple question. I am trying to create some kind of layout that would display my records from SQLite Database in separate cells. I tried to make it using TextViews, but it is not what I expect. Do you know any ideas to create 'excel like' table with headers etc? What is more i need each row to be able to select and open (My goal is to have something like catalogue with products).



final TextView dTable= (TextView) findViewById(R.id.displayTable);
final ManageDatabase md = new ManageDatabase(this);
dTable.setText("");
for(Product p: md.takeAllProducts())

dTable.setText(dTable.getText()+"n"+" "+p.getProductCode()+" "+p.getProductName()+" "+p.getQuantity()+" "+p.getExpireDate());










share|improve this question























  • what does catalogue with products have to do with "excel like"? What exactly is your issue you are facing? What errors do you get? What do you mean by saying ...but it is not what I expect.. ?
    – B001ᛦ
    Nov 9 at 15:12











  • I mean I want to create table with rows and columns, where I can click on a row and open 'additional info' about product. My issue is that I can only display data from database but in one TextView field. What I expect is something like HTML table which I can put inside inside the loop to display all records.
    – PeterMax00
    Nov 9 at 15:20










  • You can use a GridLayout
    – Augusto
    Nov 9 at 15:20














up vote
0
down vote

favorite












I got a simple question. I am trying to create some kind of layout that would display my records from SQLite Database in separate cells. I tried to make it using TextViews, but it is not what I expect. Do you know any ideas to create 'excel like' table with headers etc? What is more i need each row to be able to select and open (My goal is to have something like catalogue with products).



final TextView dTable= (TextView) findViewById(R.id.displayTable);
final ManageDatabase md = new ManageDatabase(this);
dTable.setText("");
for(Product p: md.takeAllProducts())

dTable.setText(dTable.getText()+"n"+" "+p.getProductCode()+" "+p.getProductName()+" "+p.getQuantity()+" "+p.getExpireDate());










share|improve this question























  • what does catalogue with products have to do with "excel like"? What exactly is your issue you are facing? What errors do you get? What do you mean by saying ...but it is not what I expect.. ?
    – B001ᛦ
    Nov 9 at 15:12











  • I mean I want to create table with rows and columns, where I can click on a row and open 'additional info' about product. My issue is that I can only display data from database but in one TextView field. What I expect is something like HTML table which I can put inside inside the loop to display all records.
    – PeterMax00
    Nov 9 at 15:20










  • You can use a GridLayout
    – Augusto
    Nov 9 at 15:20












up vote
0
down vote

favorite









up vote
0
down vote

favorite











I got a simple question. I am trying to create some kind of layout that would display my records from SQLite Database in separate cells. I tried to make it using TextViews, but it is not what I expect. Do you know any ideas to create 'excel like' table with headers etc? What is more i need each row to be able to select and open (My goal is to have something like catalogue with products).



final TextView dTable= (TextView) findViewById(R.id.displayTable);
final ManageDatabase md = new ManageDatabase(this);
dTable.setText("");
for(Product p: md.takeAllProducts())

dTable.setText(dTable.getText()+"n"+" "+p.getProductCode()+" "+p.getProductName()+" "+p.getQuantity()+" "+p.getExpireDate());










share|improve this question















I got a simple question. I am trying to create some kind of layout that would display my records from SQLite Database in separate cells. I tried to make it using TextViews, but it is not what I expect. Do you know any ideas to create 'excel like' table with headers etc? What is more i need each row to be able to select and open (My goal is to have something like catalogue with products).



final TextView dTable= (TextView) findViewById(R.id.displayTable);
final ManageDatabase md = new ManageDatabase(this);
dTable.setText("");
for(Product p: md.takeAllProducts())

dTable.setText(dTable.getText()+"n"+" "+p.getProductCode()+" "+p.getProductName()+" "+p.getQuantity()+" "+p.getExpireDate());







java android android-sqlite






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 10 at 9:11









Brian Tompsett - 汤莱恩

4,153133699




4,153133699










asked Nov 9 at 15:10









PeterMax00

31




31











  • what does catalogue with products have to do with "excel like"? What exactly is your issue you are facing? What errors do you get? What do you mean by saying ...but it is not what I expect.. ?
    – B001ᛦ
    Nov 9 at 15:12











  • I mean I want to create table with rows and columns, where I can click on a row and open 'additional info' about product. My issue is that I can only display data from database but in one TextView field. What I expect is something like HTML table which I can put inside inside the loop to display all records.
    – PeterMax00
    Nov 9 at 15:20










  • You can use a GridLayout
    – Augusto
    Nov 9 at 15:20
















  • what does catalogue with products have to do with "excel like"? What exactly is your issue you are facing? What errors do you get? What do you mean by saying ...but it is not what I expect.. ?
    – B001ᛦ
    Nov 9 at 15:12











  • I mean I want to create table with rows and columns, where I can click on a row and open 'additional info' about product. My issue is that I can only display data from database but in one TextView field. What I expect is something like HTML table which I can put inside inside the loop to display all records.
    – PeterMax00
    Nov 9 at 15:20










  • You can use a GridLayout
    – Augusto
    Nov 9 at 15:20















what does catalogue with products have to do with "excel like"? What exactly is your issue you are facing? What errors do you get? What do you mean by saying ...but it is not what I expect.. ?
– B001ᛦ
Nov 9 at 15:12





what does catalogue with products have to do with "excel like"? What exactly is your issue you are facing? What errors do you get? What do you mean by saying ...but it is not what I expect.. ?
– B001ᛦ
Nov 9 at 15:12













I mean I want to create table with rows and columns, where I can click on a row and open 'additional info' about product. My issue is that I can only display data from database but in one TextView field. What I expect is something like HTML table which I can put inside inside the loop to display all records.
– PeterMax00
Nov 9 at 15:20




I mean I want to create table with rows and columns, where I can click on a row and open 'additional info' about product. My issue is that I can only display data from database but in one TextView field. What I expect is something like HTML table which I can put inside inside the loop to display all records.
– PeterMax00
Nov 9 at 15:20












You can use a GridLayout
– Augusto
Nov 9 at 15:20




You can use a GridLayout
– Augusto
Nov 9 at 15:20












1 Answer
1






active

oldest

votes

















up vote
0
down vote



accepted










You can use TableLayout for it and dynamically add your content there.



First get the reference of table layout from XML file.



TableLayout myTable = (TableLayout) findViewById(R.id.mTable);


Then you can add retrieved data to the table dynamically like below



 for(Product p: md.takeAllProducts())
//create new row
TableRow tableRow = new TableRow(this);

// create new text view
TextView textView1 = new TextView(this);
textView1.setText(p.getProductCode());
//add to row
tableRow.addView(textView1);

//create another text view and add to same row
TextView textView2 = new TextView(this);
textView2.setText(p.getProductName());
tableRow.addView(textView2);

//
TextView textView3 = new TextView(this);
textView3.setText(p.getQuantity());
tableRow.addView(textView3);

//
TextView textView4 = new TextView(this);
textView4.setText(p.getExpireDate());
tableRow.addView(textView4);






share|improve this answer




















    Your Answer






    StackExchange.ifUsing("editor", function ()
    StackExchange.using("externalEditor", function ()
    StackExchange.using("snippets", function ()
    StackExchange.snippets.init();
    );
    );
    , "code-snippets");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "1"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













     

    draft saved


    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53228337%2fhow-to-make-a-table-to-display-records-from-a-sqlite-database%23new-answer', 'question_page');

    );

    Post as a guest






























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    0
    down vote



    accepted










    You can use TableLayout for it and dynamically add your content there.



    First get the reference of table layout from XML file.



    TableLayout myTable = (TableLayout) findViewById(R.id.mTable);


    Then you can add retrieved data to the table dynamically like below



     for(Product p: md.takeAllProducts())
    //create new row
    TableRow tableRow = new TableRow(this);

    // create new text view
    TextView textView1 = new TextView(this);
    textView1.setText(p.getProductCode());
    //add to row
    tableRow.addView(textView1);

    //create another text view and add to same row
    TextView textView2 = new TextView(this);
    textView2.setText(p.getProductName());
    tableRow.addView(textView2);

    //
    TextView textView3 = new TextView(this);
    textView3.setText(p.getQuantity());
    tableRow.addView(textView3);

    //
    TextView textView4 = new TextView(this);
    textView4.setText(p.getExpireDate());
    tableRow.addView(textView4);






    share|improve this answer
























      up vote
      0
      down vote



      accepted










      You can use TableLayout for it and dynamically add your content there.



      First get the reference of table layout from XML file.



      TableLayout myTable = (TableLayout) findViewById(R.id.mTable);


      Then you can add retrieved data to the table dynamically like below



       for(Product p: md.takeAllProducts())
      //create new row
      TableRow tableRow = new TableRow(this);

      // create new text view
      TextView textView1 = new TextView(this);
      textView1.setText(p.getProductCode());
      //add to row
      tableRow.addView(textView1);

      //create another text view and add to same row
      TextView textView2 = new TextView(this);
      textView2.setText(p.getProductName());
      tableRow.addView(textView2);

      //
      TextView textView3 = new TextView(this);
      textView3.setText(p.getQuantity());
      tableRow.addView(textView3);

      //
      TextView textView4 = new TextView(this);
      textView4.setText(p.getExpireDate());
      tableRow.addView(textView4);






      share|improve this answer






















        up vote
        0
        down vote



        accepted







        up vote
        0
        down vote



        accepted






        You can use TableLayout for it and dynamically add your content there.



        First get the reference of table layout from XML file.



        TableLayout myTable = (TableLayout) findViewById(R.id.mTable);


        Then you can add retrieved data to the table dynamically like below



         for(Product p: md.takeAllProducts())
        //create new row
        TableRow tableRow = new TableRow(this);

        // create new text view
        TextView textView1 = new TextView(this);
        textView1.setText(p.getProductCode());
        //add to row
        tableRow.addView(textView1);

        //create another text view and add to same row
        TextView textView2 = new TextView(this);
        textView2.setText(p.getProductName());
        tableRow.addView(textView2);

        //
        TextView textView3 = new TextView(this);
        textView3.setText(p.getQuantity());
        tableRow.addView(textView3);

        //
        TextView textView4 = new TextView(this);
        textView4.setText(p.getExpireDate());
        tableRow.addView(textView4);






        share|improve this answer












        You can use TableLayout for it and dynamically add your content there.



        First get the reference of table layout from XML file.



        TableLayout myTable = (TableLayout) findViewById(R.id.mTable);


        Then you can add retrieved data to the table dynamically like below



         for(Product p: md.takeAllProducts())
        //create new row
        TableRow tableRow = new TableRow(this);

        // create new text view
        TextView textView1 = new TextView(this);
        textView1.setText(p.getProductCode());
        //add to row
        tableRow.addView(textView1);

        //create another text view and add to same row
        TextView textView2 = new TextView(this);
        textView2.setText(p.getProductName());
        tableRow.addView(textView2);

        //
        TextView textView3 = new TextView(this);
        textView3.setText(p.getQuantity());
        tableRow.addView(textView3);

        //
        TextView textView4 = new TextView(this);
        textView4.setText(p.getExpireDate());
        tableRow.addView(textView4);







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 10 at 3:32









        Lucefer

        8001510




        8001510



























             

            draft saved


            draft discarded















































             


            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53228337%2fhow-to-make-a-table-to-display-records-from-a-sqlite-database%23new-answer', 'question_page');

            );

            Post as a guest














































































            Popular posts from this blog

            How to how show current date and time by default on contact form 7 in WordPress without taking input from user in datetimepicker

            Syphilis

            Darth Vader #20