FlowLayout
FlowLayout copied to clipboard
Add view at runtime
I am trying to add view at runtime, but it's not working properly.
TextView textView = new TextView(context); ViewGroup.LayoutParams layoutParams = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); textView.setBackgroundColor(Color.GRAY); textView.setText("New Item"); flowLayout.addView(textView,layoutParams);
I solved mine, give it a try : TextView textView = new TextView(context); FlowLayout.LayoutParams layoutParams = new FlowLayout.LayoutParams(FlowLayout.LayoutParams.WRAP_CONTENT, FlowLayout.LayoutParams.WRAP_CONTENT); textView.setBackgroundColor(Color.GRAY); textView.setText("New Item"); textView.setLayoutParams(layoutParams); flowLayout.addView(textView);
How do you set OnClick for each item?
in my case I just set each textView onclick listener, simple.