I'm developing a business profile page which contains profile image contact data and a photo gallery. I'm using Listview to check the urls from the received JSON data.
The problem is: the listview is not displayed on profile_layout. not inflated. Anyone can help?
Thanks a lot.
Here're the codes: ProfileActivity.java
 private void getGalleryJSON(String url) {
    listView = (ListView) findViewById(R.id.gallery_listview);
    galleryAdapter = new GalleryAdapter(this, R.layout.gallery_layout);
    listView.setAdapter(galleryAdapter);
    class GetGalleryJSON extends AsyncTask<String, String, String> {
        @Override
        protected void onPreExecute() {
            super.onPreExecute();
        }
        @Override
        protected String doInBackground(String... params) {
            String uri2 = params[0];
            BufferedReader bufferedReader = null;
            try {
                URL url = new URL(uri2);
                HttpURLConnection con = (HttpURLConnection) url.openConnection();
                StringBuilder sb = new StringBuilder();
                bufferedReader = new BufferedReader(new InputStreamReader(con.getInputStream()));
                String json;
                while((json = bufferedReader.readLine())!= null){
                    sb.append(json+"\n");
                }
                bufferedReader.close();
                con.disconnect();
                return sb.toString().trim();
            }catch(Exception e){
                return null;
            }
        }
        @Override
        protected void onPostExecute(String s) {
            super.onPostExecute(s);
            gallery_json = s;
            //TextView tv = (TextView)findViewById(R.id.gallery_content);
            //tv.setText(gallery_json);
            //=====================================
            //======================================
            // JSON OBJECT RECEIVED PERFECTLY
            //======================================
            //======================================
            try {
                gallery_jsonObject = new JSONObject(gallery_json);
                gallery_jsonArray = gallery_jsonObject.getJSONArray("result");
                int count = 0;
                String thumb;
                while (count < gallery_jsonArray.length()){
                    JSONObject JO = gallery_jsonArray.getJSONObject(count);
                    thumb = JO.getString("thumburl");
                    Gallery gallery = new Gallery(thumb);
                    galleryAdapter.add(gallery);
                    count++;
                }
            } catch (JSONException e1) {
                e1.printStackTrace();
            }
        }
    }
    GetGalleryJSON ggj = new GetGalleryJSON();
    ggj.execute(url);
}
This is the adapter GalleryAdapter.java
public class GalleryAdapter extends ArrayAdapter{
List list = new ArrayList();
public GalleryAdapter(Context context, int resource)
{
    super(context, resource);
}
public void add(Profiles object) {
    super.add(object);
    list.add(object);
}
@Override
public int getCount() {
    return list.size();
}
@Override
public Object getItem(int position) {
    return list.get(position);
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
    View row;
    row = convertView;
    GalleryHolder galleryHolder;
    if(row == null){
        LayoutInflater layoutInflater = (LayoutInflater)this.getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        row = layoutInflater.inflate(R.layout.gallery_layout, parent, false);
        galleryHolder = new GalleryHolder();
        galleryHolder.img_url = (TextView) row.findViewById(R.id.img_url);
        row.setTag(galleryHolder);
    }
    else {
        galleryHolder = (GalleryHolder) row.getTag();
    }
    Gallery gallery = (Gallery) this.getItem(position);
    galleryHolder.img_url.setText(gallery.getUrl());
            //=====================================
            //======================================
            // LATER I WILL USE THIS FOR IMAGEVIEW
            //======================================
            //=====        //Picasso.with(this.getContext()).load(gallery.getUrl()).into(galleryHolder.img_url);
    return row;
}
static class GalleryHolder{
    TextView img_url;
}}
And this is the Gallery.java
public class Gallery {
private String url;
public Gallery(String url)
{
    this.setUrl(url);
}
public void setUrl(String url){
    this.url = url;
}
public String getUrl(){
    return url;
}}
I use this layout on profile page
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
>
<ScrollView
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:fitsSystemWindows="true"
    android:orientation="horizontal"
    >
    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        >
        screen-wide thumb
        <LinearLayout
            android:orientation="horizontal"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:padding="10dp"
            android:id="@+id/data">contact data
        </LinearLayout>
        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:gravity="top"
            android:padding="10dp"
            android:id="@+id/content">
            <TextView
                android:id="@+id/txt_content"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:editable="false"
                android:text="Content" />
        </LinearLayout>
        <TextView
            android:id="@+id/gallery_content"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="Gallery"
            android:textAlignment="center"
            />
        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:gravity="top"
            android:padding="10dp"
            android:id="@+id/gallery">
            <ListView
                android:id="@+id/gallery_listview"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_margin="5dp"
                android:columnWidth="100dp"
                android:drawSelectorOnTop="true"
                android:gravity="center"
                android:numColumns="auto_fit"
                android:stretchMode="columnWidth"
                android:verticalSpacing="5dp"
                android:focusable="true"
                android:clickable="true"
                android:background="#FF0000"
                />
        </LinearLayout>
    </LinearLayout>
</ScrollView>
And this is the gallery_layout
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_height="85dp">
<TextView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/img_url"
     />
</RelativeLayout>
Note: I am using listview to check the urls only. I will change to GridView later
 
     
    