Search code examples
androidandroid-layoutandroid-activityandroid-widgetandroid-xml

Display UI like facebook messenger in Android java programatically


Image

http://imgur.com/llytvyQ --

I want to achieve something like this in above image

I have to loop through this json array to get all my datas; the data contained in my json array are for example

{
 'img' : http:\\.....
 'name' : XYZ
 'msg' : xyz
 'time' : abc
}

//this is where I am tring to append everything
final LinearLayout rl = (LinearLayout)main.findViewById(R.id.mainL); 

for (int i = 0; i < json.length(); i++) { 
    try {
        JSONObject c = json.getJSONObject(i);
        //here components must be created and added to view
    }catch (JSONException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}

I just want to know the how do you programmatically style the views(textview,imageview etc) like in the above image. Any Help will be appreciated


Solution

  • Ok, the image you are looking at is actually a ListView serving custom-made views.

    How does that work?
    You will need to subclass the BaseAdapter class. This subclass will contain the underlying data which in your case you are getting as a JSON-formatted reply from the web-server.

    When the getView() of the BaseAdapter subclass is called, you can inflate a layout that contains an ImageView and TextViews to display the data onscreen.