public class OccuMechanical extends android.support.v4.app.Fragment {
private View v_schedule;
private LinearLayout layout_schedule;
private ImageButton iv_add_schedule;
private int i = 0;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.fragment_occu_mechanical, container, false);
layout_schedule = (LinearLayout) v.findViewById(R.id.layout_mech_schedule);
iv_add_schedule = (ImageButton) v.findViewById(R.id.iv_add_schedule);
iv_add_schedule.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
i++;
v_schedule = LayoutInflater.from(getActivity()).inflate(R.layout.layout_mech_schedule, null);
layout_schedule.addView(v_schedule);
EditText et = (EditText) layout_schedule.getRootView().findViewById(R.id.layout_description);
et.setText("Test: " + String.valueOf(i));
}
});
return v;
}
}
idk,如果我的标题正确,但这是我正在做的... 当我点击“添加更多设备”时,它会向我的应用添加布局 我想将所有EditText放入RootView中添加的布局中, 我尝试设置文本进行测试,但是第一个rootView的第一个editText是唯一的更新。上面列出的片段中的所有代码。所附图片是此代码的结果。
答案 0 :(得分:0)
我已经按照建议使用* RecyclerView来完成此任务,例如 @hjchin 。谢谢!