android listview onclick button - android

Edited, thnx 4 de answer but wht I meant is this-have populated listview with image,Id,and name of candidates from mysql database. Made a custom adapter with android vote button, which auto generate on every candidate in the listview. So what I want is when a voter clicks on the vote button either Id, or name is sent 2 database and then increase number of votes by +1 in the vote field of the database. Android voting app using php(android and php)Any1 pliz help.

Very Simple You can do this by getting your current count from database then increment the same in your Android code and then update the database with new value that you just incremented.

Related

Android sqlite pagination in TextView

I am using Android studio with SQLite database is built-in, I am fetching some text from a table of 2 columns into TextView.
I want to use next and previous button
When the Activity starts, it loads the first record of a table in TextView but when I click on next button it should fetch next row of the table in TextView and when I click previous it should fetch the previous row of the table.
I am new to Android I searched about that but unfortunately found nothing.
try this. it could help you.
when a user enters in Activity fetch all data from Database and store that data in ArrayList at particular index . On click of Next Button get data from ArrayList according to it's index.

Firebase User Favourites List

Looking for a push in the right direction for creating a list of user favourites in Android. I have a list of items from a database which a user can scroll through and add to their favourites so when they log into their account they will be presented with a list of their favourite items. Is it possible to add an array or collection of some sort to the user so when they favourite an item then the primary id is added to some favourites parameter in their account which can be retrieved when they log in?
Sorry if this question is a bit basic, I am still new and am really only making this app to teach myself how to write android apps that use a database.
Thanks in advance!
Since you already have a database. I would add a new table or column to your existing table that would be set to 'true' or 'false' depending on whether or not the item is a user favorite.
This is better than a SharedPreferences because if you store row IDs you now have to manage that information in two places.
Additionally it's easy to get all items or just favorited items using an SQL query.
https://developer.android.com/training/data-storage/sqlite.html

Using Arraylist display data of questions and answers

i want to show questions in list view from sqlite and under every question there is editText field to submit answer. i am fetching questions from local db through array list, but problem is when user will submit answer then next question will be displayed in list and so on.
kindly help me how to do it?
Store data in DB in sequence with number as primary key
While fetching question from SQLite in query add
limit Question_Number
Question_Number is the question limit you want to display.
First time add limit 1
Everytime when user enter answer the question and click ok.
Fetch the data from database using limit currentPosition +1
i did it by passing a variable in constructor. and showed 3 question one after the other in my scenario. and it solved my problem.

Send MySQL query to a remote database using listview [duplicate]

This question already has answers here:
Sending Queries to a database from android
(2 answers)
Closed 9 years ago.
I have a ListView of sports and when pressed I would like it to send a MySQL query to my remote database and send back the rest of the data about that sport so like:
SELECT * FROM SportsTable WHERE name="????"
So I would like a way to replace the '????' with the option I have pressed in the listview
How would I go about doing this?
Thanks,
Zach
I'd advise you to read up on some tutorials before trying random things.
You can register for the OnItemClickListener which will hand you the pressed position.
From there, you can use the position to get the item from your original collection.
Any ListView tutorial will show you this.
Secondly, I hope you're not trying to connect straight into some remote DB or send a total query to some webservice which just takes any input as a query.
So I would like a way to replace the '????' with the option I have
pressed in the listview
How would I go about doing this?
So most likely you are looking for parametrized statements(and i recommend use them). Simply you created statement like this:
select * from Sports where name = ?
? is called placeholder that will be replaced with value from ListView. Probably you are using PHP so you'll use bindParam() function for bind parameter to query. Have look at PDO
And to be able to handle clicks over ListView, you need to use OnItemClickListener and in onItemClick method you can get item at clicked position from your Collection.

How to generate dynamic list in android based on entries from database

I want to generate a list from a table in my database. That list should contain all rows of one column i.e table: Contact column name: contact_name. Next I want to show all of the contact_names. But each value should be click-able. When a user clicks on it, it should print in next activity the contact_name, contact_address etc.
I am new in android. So all help will be appreciated. Thanks in advance :)
Try using SimpleCursorAdapter or CursorAdapter

Categories

Resources