How do I limit the number of lines in a listview

Asked

Viewed 225 times

1

I have a listview that is adapted with a cursoradapter ...it selects everything from the database and adapt in my listview .... but I wanted to limit the amount of lines that appear on my listview ... something like that. wanted q select all data I have but showing only 10 ... independent of the number of data in the database .... thanks

  • Are you using Simpleadapter or Customadapter for your Listview? It would be interesting if you put something of your code here.

  • You can limit the lines directly in the database query, which is simpler

  • Use LIMIT and make your rule right in the database!

1 answer

1


Just limit the SQL query to the database. In your case it would look like this:

SELECT coluna FROM tabela ORDER BY algo LIMIT 10

If you are using the query() method of the Sqlitedatabase class, you can do the same query above that way:

db.query (null, 
            tabela, 
            New String[]{coluna}, 
            null, 
            null, 
            null, 
            null, 
            algo, 
            "10");

Browser other questions tagged

You are not signed in. Login or sign up in order to post.