FlowLayout with adapter in Android

I'm looking for any library that can help me create a FlowLayout with an adapter like a GridView, but I want to arrange the items in the flow! What do you think is the best way to do it (FreeFlow)? I created a StickyListHeadersListView with an adapter:

   @Override
public View getView(int position,  View convertView, final ViewGroup parent) {
    FiltersChildViewHolder holder;
    if (convertView == null) {
        final View[] temp = new View[1];
        mActivity.runOnUiThread(new Runnable() {
            @Override
            public void run() {
             temp[0] = mInflater.inflate(R.layout.item_filters_layout, parent, false);
            }
        });
      convertView = temp[0];

        holder = new FiltersChildViewHolder();
        holder.flFilters_IFL = (FlowLayout) convertView.findViewById(R.id.flFilters_IFL);

        convertView.setTag(holder);
    } else {
        holder = (FiltersChildViewHolder) convertView.getTag();
    }


    ArrayList<FilterModel> filterModels = getFiltersForCategory(position);

    FilterLayoutAdapter adapter = new FilterLayoutAdapter(mActivity, filterModels);
    adapter.setOnFiltersChangedListener(mFiltersChangedListener);
    adapter.setIsDefault(isDefault);
    holder.flFilters_IFL.setAdapter(adapter);

    return convertView;
}

      

This is the getView () method in my adapter! Each list item is a FlowLayout, and the FilterLayoutAdapter adds views to this FlowLayout, this works for me, this way the items are ordered in the flow, but the ListView is very loose when I view the next list item, because all childViews are immediately pumped into the FlowLayout, and thera - 100 childView!

+3


source to share


2 answers


Hi, here is an example using a custom library that acts like a List GitHubLibrary TagLayout

  • Example code : -

mFlowLayout.setAdapter(new TagAdapter<String>(mVals) { @Override public View getView(FlowLayout parent, int position, String s) { TextView tv = (TextView) mInflater.inflate(R.layout.tv, mFlowLayout, false); tv.setText(s); return tv; } });

Using the code below, you can pre-set the selection you want: -



mAdapter.setSelectedList(1,3,5,7,8,9);

      

Will show the result as below: -

enter image description here

+1


source


Use this section code at the end of the getView method before return view;

.

Animation animationY = new TranslateAnimation(0, 0,
                        parent.getHeight() / 4, 0);
                animationY.setDuration(1000);
                view.startAnimation(animationY);

      



where parent will be

public View getView(final int position, View convertView,
                ViewGroup parent)

      

0


source







All Articles