我已创建添加到TextViews
的动态FlowLayout
数组列表。现在,当点击EditText
时,我必须在每个TextView
左侧添加一个ImageView
。
代码:
FlowLayout.LayoutParams params = new FlowLayout.LayoutParams(
FlowLayout.LayoutParams.WRAP_CONTENT, FlowLayout.LayoutParams.WRAP_CONTENT);
params.setMargins(5, 5, 5, 5);
mFlowLayout.removeAllViews();
View[] view = new View[2];
for (int i = 0; i < 2; i++) {
view[i] = LayoutInflater.from(getActivity()).inflate(R.layout.item_rich_element_edit_flow_layout
, mFlowLayout, false);
view[i].setId(i);
view[i].setTag(i);
TextView textView = view[i].findViewById(R.id.text_view_attribute_name);
ImageView imageView = view[i].findViewById(R.id.image_view_left_cursor);
imageView.setTag(i);
imageView.setOnClickListener(view1 -> addView((Integer) view1.getTag(), view1));
textView.setText(element.getElementName());
mFlowLayout.addView(view[i]);
}