Emad Ha
Emad Ha

Reputation: 1222

How to start an android project coders view

I've been searching for the past week on how to develop an android project, read some on android developers page and on other websites like here, but no text was complete.

i have this project - i'm a php developer not a java, but could understand a bit about java lately.

the thing is i want to develop an android app using my website, i did output a json type data from my website, and gonna use them on the android app, i did the async request on android and could read the data form the website but :

first question: how to parse the json data correctly and convert it to array on android, i did that through:

Iterator<String> itr = myObject.keys();
   while (itr.hasNext()) {
      ...

i don't know if that's the correct way, when i try to convert my json object to array, it gives me type mismatch.

second and more importantly:

how can create a "Block" like facebook posts style, or twitter style blocks, you know - blocks of json data, is it a linearlayout ? what do i call it ? and how can i add it to the UI dynamically, cuz these blocks are pulled from the website json data. so they are arrays...of blocks..

i'm kinda confused still, i need a start point.

Thank you!

Upvotes: 0

Views: 50

Answers (2)

Ezzored
Ezzored

Reputation: 925

First question: you should use a library to parse JSON, it's simpler that way. Try gson. You should create a class, which holds the parsed object, like:

public class Taxi implements Serializable {
    private static final long serialVersionUID = 1L;

    @SerializedName("idTaxi")
    private Integer idTaxi;

    @SerializedName("name")
    private String name;

    //getter, setters, constructor, etc
}

Then when you get the JSON object, you can parse it:

Gson gson = new Gson();
Reader reader = new InputStreamReader(SOURCE_STREAM);
Taxi[] response = gson.fromJson(reader, Taxi[].class);

Second question: i think a ListView would be good for you. You can read a full tutorial about it here

Upvotes: 0

Lena Bru
Lena Bru

Reputation: 13937

excellent tutorial for beginners for android development

http://thenewboston.org/list.php?cat=6

and for your first question - how to parse json data correctly,

you can try using gson to convert the json data into POJO

otherwise you'd have to do myObject.opt(key) to make sure it is there

Upvotes: 1

Related Questions