title: Dynamic ListView issue on Android
body: <p>Currently I am working on an Android app and use parse as backend where I have created a <code>ListView</code> of  nearby places dynamically. But I face the following design issue: When the user clicks on a place, a view must appear under the clicked item. </p>
  
  <p>And I have faced a problem with grouping the place, as you can see in figure 1, there are many branches for HSBC bank. In which case they are under HSBC.</p>
  
  <p>I have tried expandable ListView before, but it does not give much customization for child view , just simple one. </p>
  
  <p>my BaseAdapter:</p>
  
  <pre><code>import java.util.ArrayList;
  import java.util.List;
  
  import com.parse.ParseGeoPoint;
  
  import android.content.Context;
  import android.content.Intent;
  import android.view.LayoutInflater;
  import android.view.View;
  import android.view.View.OnClickListener;
  import android.view.ViewGroup;
  import android.view.ViewManager;
  import android.widget.BaseAdapter;
  import android.widget.ImageView;
  import android.widget.TextView;
  import android.widget.Toast;
  
  public class ListViewAdapter extends BaseAdapter {
  
      // Declare Variables
      Context context;
      LayoutInflater inflater;
      //ImageLoader imageLoader;
      private List&lt;AnywallPost&gt; AnywallPostlist = null;
      private ArrayList&lt;AnywallPost&gt; arraylist;
  
      public ListViewAdapter(Context context,
              List&lt;AnywallPost&gt; AnywallPostlist) {
          this.context = context;
          this.AnywallPostlist = AnywallPostlist;
          inflater = LayoutInflater.from(context);
          this.arraylist = new ArrayList&lt;AnywallPost&gt;();
          this.arraylist.addAll(AnywallPostlist);
  
      }
  
      public class ViewHolder {
          TextView distance;
          TextView name;
  
      }
  
      @Override
      public int getCount() {
          return AnywallPostlist.size();
      }
  
      @Override
      public Object getItem(int position) {
          return AnywallPostlist.get(position);
      }
  
      @Override
      public long getItemId(int position) {
          return position;
      }
  
      public View getView(final int position, View view, ViewGroup parent) {
          final ViewHolder holder;
          final View row=view;
  
          if (view == null) {
              holder = new ViewHolder();
              view = inflater.inflate(R.layout.user_custom, null);
              // Locate the TextViews in listview_item.xml
              holder.distance = (TextView) view.findViewById(R.id.disView);
              holder.name = (TextView) view.findViewById(R.id.nameView);
  
  
              view.setTag(holder);
          } else {
              holder = (ViewHolder) view.getTag();
          }
          // Set the results into TextViews
  
          holder.name.setText(AnywallPostlist.get(position).getText());
          holder.distance.setText(AnywallPostlist.get(position).getDis());
  
  
          //Listen for ListView Item Click
          view.setOnClickListener(new OnClickListener() {
  
              @Override
              public void onClick(View arg0) {
  
                  Toast.makeText(context,AnywallPostlist.get(position).getText(), Toast.LENGTH_LONG).show();
  
  
              }
          });
          return view;
      }
  
  }
  </code></pre>
  
  <p>.</p>
  
  <pre><code>import com.parse.ParseClassName;
  import com.parse.ParseGeoPoint;
  import com.parse.ParseObject;
  import com.parse.ParseQuery;
  import com.parse.ParseUser;
  
  /**
   * Data model for a post.
   */
  @ParseClassName("places")
  public class AnywallPost extends ParseObject {
  
    public String getText() {
      return getString("text");
    }
  
    public void setText(String value) {
      put("text", value);
    }
  
  public String getBank() {
      return getString("bank");
    }
  
    public void setBank(String value) {
      put("bank", value);
    }
  
    public ParseUser getUser() {
      return getParseUser("user");
    }
  
    public void setUser(ParseUser value) {
      put("user", value);
    }
  
  
    public String getType()
    {
      return getString("type");  
    }
  
    public void setType(String value)
    {
      put("type",value);
    }
  
    public ParseGeoPoint getLocation() {
      return getParseGeoPoint("location");
    }
  
    public void setLocation(ParseGeoPoint value) {
      put("location", value);
    }
  
  
    public String getDis()
    {
      return getString("dis");  
    }
  
    public void setdis(String value)
    {
      put("dis",value);
    }
  
    public static ParseQuery&lt;AnywallPost&gt; getQuery() {
      return ParseQuery.getQuery(AnywallPost.class);
    }
  }
  </code></pre>
  
  <p>.</p>
  
  <pre><code>switch (getItemViewType(position)) {
              case 0:
                  Bank bank = (Bank) getItem(position);
                  holder.name.setText(bank.name);
                  String str = String.valueOf(bank.numBranches);
                  holder.cn.setText(str);
                  imageLoader.DisplayImage(bank.image,
                          holder.logo);
                  Toast.makeText(getActivity(), "img"+bank.image,Toast.LENGTH_LONG).show();
                  // ... set the image here
                  // ... set the number of branches here
                  break;
              case 1:
                  branch = (AnywallPost) getItem(position);
                  holder.name.setText(branch.getText());
                  holder.distance.setText(branch.getDis());
                  holder.b.setText(branch.getbranch());
                  imageLoader.DisplayImage(branch.getimg(),
                          holder.logo);
                  break;
              case 2:
                  branch = (AnywallPost) getItem(position);
                  holder.name.setText(branch.getText());
                  holder.distance.setText(branch.getDis());
                  holder.b.setText(branch.getbranch());
                  imageLoader.DisplayImage(branch.getimg(),
                          holder.logo);
                  // ... set values for all the expanded view widgets too
                  break;
          }
  </code></pre>
  
  <p>I have used this code to get image from parse and I add it to AnywallPost </p>
  
  <pre><code>ParseFile image = (ParseFile) country.get("image");
  
  AnywallPost map = new AnywallPost();
  
  map.setimg(image.getUrl());
  </code></pre>
  
  <p>then, I used this code to load the image and it worked fine</p>
  
  <pre><code>imageLoader.DisplayImage(AnywallPostlist.get(position).getimg(),
                  holder.logo);
  </code></pre>