Android Sql database just gives last data

max rian

I am trying to receive all data of my sqli database, but strangely I just get the last data if I try to print it on a textview.

But trying to log the data gives mme the full database which is correct,

I just cannot print them all.

code for this:

        public View onCreateView(LayoutInflater inflater, ViewGroup container,
                                 Bundle savedInstanceState) {

            DatabaseHandler db = new DatabaseHandler(getActivity());
            View rootView = inflater.inflate(R.layout.fragment_main, container, false);
            int currentView = getArguments().getInt(ARG_SECTION_NUMBER);

            List<Contact> contacts = db.getAllContacts();

            if (currentView == 1) {
                for (Contact cn : contacts) {
                    TextView asd = (TextView) rootView.findViewById(R.id.section_label);
                    String test = "Id: " + cn.getID() + cn.getJokeCat01();
                    System.out.println(test);
                    asd.setText(test);
                }
            }
        }

Again with Systemoutprint I get all data in the console, but if I try to setText I just get the last data.

Andrew Lobley

Since 'test' is getting declared inside the loop, every time the following line

String test = "Id: " + cn.getID() + cn.getJokeCat01();

runs, it will put a new value in the variable, that you are showing using setText(), which will remove the earlier text and display the current text.

In my view, the following might help you achieve what you are looking after:

if (currentView == 1) {
  String test="";
  for (Contact cn : contacts) {
    TextView asd = (TextView) rootView.findViewById(R.id.section_label);
    test += "Id: " + cn.getID() + cn.getJokeCat01();
    System.out.println(test);

  } // end of for

  Witze.setText(test);

}  // end of if

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

SQL division gives answer only for the last row

From Dev

SQL division gives answer only for the last row

From Java

SQL - does database extract repeating joined data multiple times or just once?

From Dev

SQL in statement for last data

From Dev

postgresql connect to database that just created in .sql file

From Dev

How to retrieve row data from SQL database - Android

From Dev

get data from android app and store it in sql database using php

From Dev

Error while deleting last two rows data with condition from database in Android it deletes only 1 row

From Dev

sql statement query last data

From Dev

sql statement query last data

From Dev

Update a data in SQL database

From Dev

How to select just current month data in SQL?

From Dev

How to select just current month data in SQL?

From Dev

Sql: display just the changed data in each row

From Java

picking data in last array (android)

From Dev

SQL Server database last updated date time

From Dev

sql show the last 4 rows from database

From Dev

Data from database of last 10 newest

From Dev

Data from database of last 10 newest

From Dev

Android SQL database organization

From Dev

Android SQL database error

From Dev

Android SQL database organization

From Dev

SQL database in Android

From Dev

Insert data into database in Android

From Dev

how to move data from one database (main serevr (sql)) to another in android database (local (sqlite))

From Dev

How to insert data into sqlite database just one time

From Dev

select from database just can get first data

From Dev

phpMyAdmin gives export.php instead of database sql dump

From Dev

data from database echoed with htmlentities gives weird signs in hebrew

Related Related

HotTag

Archive