Home > Mobile >  Display Multiple chips/tags in single line in android using autocomplete text view
Display Multiple chips/tags in single line in android using autocomplete text view

Time:11-03

i want to display multiple chips may two or more in single line and rest in the subsequent lines. Please see the attached image, i want the same as displayed in the image.enter image description here

CodePudding user response:

Use FlexboxLayoutManager with RecyclerView.

        val layoutManager = FlexboxLayoutManager(this)
        layoutManager.flexDirection = FlexDirection.ROW
        layoutManager.flexWrap = FlexWrap.WRAP
        binding.rvFilterItem.layoutManager = layoutManager
        binding.rvFilterItem.adapter = tagAdapter

CodePudding user response:

For display multiple chips two or more in single line and rest in the subsequent lines use FlexboxLayoutManager with Recyclerview.

public class YourActivity extends AppCompatActivity {
RecyclerView recyclerView;
ArrayList<String> arrayList = new ArrayList<>();
CustomAdapter adapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
recyclerView = findViewById(R.id.recyclerView);
favArray();
FlexboxLayoutManager layoutManager = new FlexboxLayoutManager(this);
layoutManager.setFlexDirection(FlexDirection.ROW);
layoutManager.setJustifyContent(JustifyContent.CENTER);
layoutManager.setAlignItems(AlignItems.CENTER);
recyclerView.setLayoutManager(layoutManager);
adapter = new CustomAdapter(YourActivity.this, arrayList);
recyclerView.setAdapter(adapter);
}
private void favArray() {
arrayList.add("The dark knight");
arrayList.add("The god father");
arrayList.add("12 Angry Man");
arrayList.add("Fight club");
arrayList.add("Star Wars");
arrayList.add("The god father : Part 2");
arrayList.add("The dark knight");
arrayList.add("The god father");
arrayList.add("The god father : Part 2");
}
}

  • Related