[Q] Extract JSON data and display in ListView with Searchbox - Java for Android App Development

Hi Everyone,
I am currently a very new starter in the Android App Development stage. I have tried to develop a ListView with Searchbox facility to search data that comes from a specific URL in the form of JSON data. I managed to understand displaying this data in ListView, but adding a search facility is something I'm struggling to grasp somehow.
The code attached is a reference code I am trying to tune before I move on to actually developing my app. However, it doesn't seem to work on the emulator, giving me the error that the MainActivity file has stopped working.
I am unsure if there is a fundamental error somewhere, and would be really grateful to get some advice on this. I have looked online and can't seem to find a good resource that explains merging ListView with JSON data effectively with a Searchbox.

ajitmenezes said:
Hi Everyone,
I am currently a very new starter in the Android App Development stage. I have tried to develop a ListView with Searchbox facility to search data that comes from a specific URL in the form of JSON data. I managed to understand displaying this data in ListView, but adding a search facility is something I'm struggling to grasp somehow.
The code attached is a reference code I am trying to tune before I move on to actually developing my app. However, it doesn't seem to work on the emulator, giving me the error that the MainActivity file has stopped working.
I am unsure if there is a fundamental error somewhere, and would be really grateful to get some advice on this. I have looked online and can't seem to find a good resource that explains merging ListView with JSON data effectively with a Searchbox.
Click to expand...
Click to collapse
You should implement the search on the listview adapter, not on the activity itself.
Take a look at the following article:
http://www.mokasocial.com/2010/07/arrayadapte-filtering-and-you/

Related

Eclipse question - new android project

So I've been reading a book and have a question about a setting that hasn't been covered. I search googler, but couldn't find anything that explained it.
Under Properties, you have Application name, Package name, and Create Activity.
Where can I find more info about this? (Activity class' that apply to droid and how to use them). I've been able to make the example activities but they don't use that field. So I'm a little lost as to what it is.
Thanks!
GhettoBSD said:
So I've been reading a book and have a question about a setting that hasn't been covered. I search googler, but couldn't find anything that explained it.
Under Properties, you have Application name, Package name, and Create Activity.
Where can I find more info about this? (Activity class' that apply to droid and how to use them). I've been able to make the example activities but they don't use that field. So I'm a little lost as to what it is.
Thanks!
Click to expand...
Click to collapse
Have you been to http://developer.android.com/index.html read up there iam sure it explains everything to get you started
Application Name
This is the human-readable title for your application — the name that will appear on the Android device.
Package Name
This is the package namespace (following the same rules as for packages in the Java programming language) that you want all your source code to reside under. This also sets the package name under which the stub Activity will be generated.
Your package name must be unique across all packages installed on the Android system; for this reason, it's important to use a standard domain-style package for your applications. The example above uses the "com.example" namespace, which is a namespace reserved for example documentation — when you develop your own applications, you should use a namespace that's appropriate to your organization or entity.
Create Activity
This is the name for the class stub that will be generated by the plugin. This will be a subclass of Android's Activity class. An Activity is simply a class that can run and do work. It can create a UI if it chooses, but it doesn't need to. As the checkbox suggests, this is optional, but an Activity is almost always used as the basis for an application.
I have been there, but I'd like more information.
Create Activity
This is the name for the class stub that will be generated by the plugin. This will be a subclass of Android's Activity class. An Activity is simply a class that can run and do work. It can create a UI if it chooses, but it doesn't need to. As the checkbox suggests, this is optional, but an Activity is almost always used as the basis for an application.
Click to expand...
Click to collapse
Trying to get more info as to which classes are available and what they're for in general.
Guess I'll keep reading my book "Beginning Android" lol
Thanks

Creating background thread

Hi
I new to android development. Presently i am working on android project and i want to create a background thread which invokes the web service and get the data and insert in to array list. From foreground i need to fetch the data from array list and display in the list view.
I tried to create a background thread. but the problem is all code has execute finally my background thread start executing.
Can anybody have sample program for background thread or anybody give the sample idea for how to do the above concept?
Thanks
mindus
The strategy I like to use is to implement a message handler as part of the main activity (using the Handler() class), then send messages to the handler from the thread to update the activity based on thread events.
ASyncTask
The way i would do this is to use ASyncTask from the android sdk, google has a pretty good example in the developer documentation. The onPostExecute method runs on the UI thread when the thread has finished executing, so you could use this to tell your adapter that theres data to be put in the listview.
Sorry i can't post the link because im new here

What Topic Do I Need To Tackle To Develop This Kind Of App?

The harvard university android app from google play store. (I can't seem to post any outside link yet for this account)
I want to create one for may school but I'm just starting to learn android programming, so guys I need your help on the topics that I need to study to create an app like that. I greatly appreciate any kind of comments. Cheers!
clonedaccnt said:
The harvard university android app from google play store. (I can't seem to post any outside link yet for this account)
I want to create one for may school but I'm just starting to learn android programming, so guys I need your help on the topics that I need to study to create an app like that. I greatly appreciate any kind of comments. Cheers!
Click to expand...
Click to collapse
Fragments, ListViews, JSON parsing (for communication with the web server to download news etc), Android SQLite databases (I suggest using this to store the information from the webserver locally so the app does not require a constant internet connection to view a news article for example), Google Cloud Messaging notifications, notifications, encryption.
There are lots more but these are some of the main ones. In addition I would not advise trying to copy the "look" or aesthetics of the Harvard application as it frankly looks disgusting, whoever designed that needs a course in UI design
any book suggestions?? im only studying at home and wanted to start studying android app development
m0nm0npalam0n said:
any book suggestions?? im only studying at home and wanted to start studying android app development
Click to expand...
Click to collapse
Android Application Development for Dummies and Learn Java for Android Development are 2 that I have in ebook form, though I can't say I've used them much as I don't really learn by reading books, more like looking at the source code of other apps and messing with it to see what happens
Android Application Development for Dummies goes through a wide range of topics including widgets, SQLite storage, possibly SharedPreferences (can't remember), ListView etc but does assume that you can at least follow what the sample code is doing - the sample code is commented but if you have not done any coding at all before then you probably should learn the basics of Java before reading it
Jonny said:
Android Application Development for Dummies and Learn Java for Android Development are 2 that I have in ebook form, though I can't say I've used them much as I don't really learn by reading books, more like looking at the source code of other apps and messing with it to see what happens
Android Application Development for Dummies goes through a wide range of topics including widgets, SQLite storage, possibly SharedPreferences (can't remember), ListView etc but does assume that you can at least follow what the sample code is doing - the sample code is commented but if you have not done any coding at all before then you probably should learn the basics of Java before reading it
Click to expand...
Click to collapse
thanks man! this really helps
Jonny said:
Fragments, ListViews, JSON parsing (for communication with the web server to download news etc), Android SQLite databases (I suggest using this to store the information from the webserver locally so the app does not require a constant internet connection to view a news article for example), Google Cloud Messaging notifications, notifications, encryption.
There are lots more but these are some of the main ones. In addition I would not advise trying to copy the "look" or aesthetics of the Harvard application as it frankly looks disgusting, whoever designed that needs a course in UI design
Click to expand...
Click to collapse
Thank you very much for the reply, I'm really thankful for the information that you share. Can you please clear this one for me?
I suggest using this to store the information from the webserver locally so the app does not require a constant internet connection to view a news article for example
Click to expand...
Click to collapse
clonedaccnt said:
Thank you very much for the reply, I'm really thankful for the information that you share. Can you please clear this one for me?
Click to expand...
Click to collapse
When you get data from a server to an Android app you use php for the server code - for example you can use php/mysql to run a search for calendar events in the database and return those events. Then you need to use php's JSON encode function to send the data in a JSON array.
The output should look something like this - this is the output of the calendar database for my school:
http://wgsb.cobainschofield.com/android_db/get_calendar.php (note this is not the live schools site, its the test server the guy who maintains the live site allows me to mess with err use).
You would then use a JSON parser class and an AsyncTask from within the app to "download" the content of the JSON array and then display it in a listview or textview etc.
Now obviously to get this information requires an internet connection yes? So every time someone wanted to check for an event on the calendar or read a news article for example they would need a working internet connection to receive the output of the get_calendar script, this is inefficient and bad design as it does not allow for offline viewing of the data.
Therefore what you can do is use androids SQLite implementation to create a local sql database then the first time you need to get the data from the webserver, you connect to the internet and get the output of the php script, the using the JSON parser class you store the information in the sqlite database then get the information from the database to display to the user.
By this way users can view news articles or calendar events offline and you only need to connect to the internet to refresh the information
I've uploaded screenshots in the attachments of how I've done it for my school's app.
That made it clear! Thank you very much.

java http to pull website data

hello guys
i am having trouble understanding how such apps work and what i need to start developing one
i've learned that you can pull website information using it's API in JSON format and display it
but if the website does not provide an API is possible to get the JSON data of any website? is it done through http request ?
i was also trying to connect my application to several news websites that keeps posting news update is it possible to read the information each time it is updated ?
and what should i know besides java to be able to connect my app to any website get information from this website and display the result regarding if it has an API or not
example : connect to a news website pull the newly posted news and display it or connect to a gaming website get the top 10 games and display them
thank you for your help
ghattas.akkad said:
hello guys
i am having trouble understanding how such apps work and what i need to start developing one
i've learned that you can pull website information using it's API in JSON format and display it
but if the website does not provide an API is possible to get the JSON data of any website? is it done through http request ?
i was also trying to connect my application to several news websites that keeps posting news update is it possible to read the information each time it is updated ?
and what should i know besides java to be able to connect my app to any website get information from this website and display the result regarding if it has an API or not
example : connect to a news website pull the newly posted news and display it or connect to a gaming website get the top 10 games and display them
thank you for your help
Click to expand...
Click to collapse
If the site you're scraping doesn't provide JSON then you can query the site using HTTP. Something like this.
Code:
URL url = new URL(target);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
InputStream in = new BufferedInputStream(connection.getInputStream());
laidlow said:
If the site you're scraping doesn't provide JSON then you can query the site using HTTP. Something like this.
Code:
URL url = new URL(target);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
InputStream in = new BufferedInputStream(connection.getInputStream());
Click to expand...
Click to collapse
thank youu
html parsing is very annoying especially when dealing with a lot of websites in a single app
i was looking for an easier method in which i can access the websites databases pull data and post it but i think if they dont have an API for that they wont give me that permission
ghattas.akkad said:
thank youu
html parsing is very annoying especially when dealing with a lot of websites in a single app
i was looking for an easier method in which i can access the websites databases pull data and post it but i think if they dont have an API for that they wont give me that permission
Click to expand...
Click to collapse
If you want an awesome library that helps you using http requests, take a look at Volley, which is really easy to use on all API levels. I didn't raed through it, but to me it sounds like you want to have some kind of RSS reader functionaly, take a look at this tutorial for instance.

Registering devices with GCM error

Hello everybody,
I'm experimenting with Google Cloud Messaging and I was following the tutorial at https :// github. com/ GoogleCloudPlatform/gradle-appengine-templates/blob/master/GcmEndpoints/README.md (I beg pardon but I can't post links). Unfortunately I spent the last two days struggling with solving all the dependencies but I still miss one.
In this code (taken from the tutorial at point 2.2) I cannot resolve the class "Registration"; I've been trying looking for it but given such a vague name I got back millions results that had little to do with my problem.
I also tried to add to my project all the suggested libraries but none of them contained the class I need.
Code:
public GcmRegistrationAsyncTask() {
Registration.Builder builder = new Registration.Builder(AndroidHttp.newCompatibleTransport(), new AndroidJsonFactory(), null)
// Need setRootUrl and setGoogleClientRequestInitializer only for local testing, otherwise they can be skipped
.setRootUrl("h t t p : / / 10.0.2.2:8080/_ah/api/")
.setGoogleClientRequestInitializer(new GoogleClientRequestInitializer() {
@Override
public void initialize(AbstractGoogleClientRequest<?> abstractGoogleClientRequest) throws IOException {
abstractGoogleClientRequest.setDisableGZipContent(true);
}
});
// end of optional local run code
regService = builder.build();
}
Could somebody point me in the right direction?
Thanks in advance for the help!
Bye
Mario
I was just following the same instructions today and I am experiencing the same problem unfortunately.
thvranken said:
I was just following the same instructions today and I am experiencing the same problem unfortunately.
Click to expand...
Click to collapse
Well, at least it means probably we are not dumb
At any rate if I should find something I'll post it here so it's available to whoever needs it and pls do the same...
Hmm.. I couldn't find a "Registration" class or import anywhere in their source code so it may be included in one of the dependencies, try checking your build.gradle files against the one given in their source code to check for the correct dependencies.
In any case, their method is (IMO) an extremely weird and complicated way of doing something very simple, if you haven't found the solution by Monday (when I should have more free time) I'll put together a package (including the html/php/MySQL server back-end files) with how I managed to do GCM messaging (which includes multicast messages)
Jonny said:
Hmm.. I couldn't find a "Registration" class or import anywhere in their source code so it may be included in one of the dependencies, try checking your build.gradle files against the one given in their source code to check for the correct dependencies.
In any case, their method is (IMO) an extremely weird and complicated way of doing something very simple, if you haven't found the solution by Monday (when I should have more free time) I'll put together a package (including the html/php/MySQL server back-end files) with how I managed to do GCM messaging (which includes multicast messages)
Click to expand...
Click to collapse
Hi Jonny, tnx for taking time and having a look! I checked the gradle file but it seemed everything in order...
At any rate I started studying better the code (I should have done it earlier actually) and noted that in the backend Android Studio created before a class with the methods I invoke in the app and before the declaration there is annotation:
Code:
@Api(name = "registration", version = "v1", namespace = @ApiNamespace(ownerDomain = "backend.rtalert.rt_finance.com", ownerName = "backend.rtalert.rt_finance.com", packagePath=""))
public class RegistrationEndpoint {
private static final Logger log = Logger.getLogger(RegistrationEndpoint.class.getName());
Now, searching on the web seems like I would somehow need to compile the backend module and import it as a lib into my app (despite is all within the same project). I imported both the zip file and the discovery one and then synced gradle, but still nothing.
Tomorrow after a few hours sleep I'll try again...
Good night
Mario
Ok apologies for being a bit late, life's been busier than I was expecting over the last few days...
Anyway, the web server files are all located in the following zip file >>> http://darkforest-roms.co.uk/Misc/AndroidGoogleColudMessaging.zip
There is also a table.txt file that contains the MySQL database base table I'm using - the setup is for an app for my school where the staff can send messages to individual year groups or to all year groups.
Assuming whatever webhosting service you are using has phpMyAdmin or similar you can just change the table columns in the table.txt file and import it. Then you need to go through register.php, update.php, possibly unregister.php and index.php to modify the website code to your specific application.
You will also need to edit the parameters in config.php for your Google API key and database name, user and password.
Thats it for the website side code, give me a couple of days to sort out the app-side java code, I need to modify some stuff in my current code before uploading it
Jonny said:
Ok apologies for being a bit late, life's been busier than I was expecting over the last few days...
Anyway, the web server files are all located in the following zip file >>> [
There is also a table.txt file that contains the MySQL database base table I'm using - the setup is for an app for my school where the staff can send messages to individual year groups or to all year groups.
Assuming whatever webhosting service you are using has phpMyAdmin or similar you can just change the table columns in the table.txt file and import it. Then you need to go through register.php, update.php, possibly unregister.php and index.php to modify the website code to your specific application.
You will also need to edit the parameters in config.php for your Google API key and database name, user and password.
Thats it for the website side code, give me a couple of days to sort out the app-side java code, I need to modify some stuff in my current code before uploading it
Click to expand...
Click to collapse
Hi Jonny, don't worry, I was quite busy these days myself, plus I really appeciate your help... In the weekend I'll set it up so I can test it and let you know...
Thanks again
Mario

Categories

Resources