Reputation: 681
I made a custom view to satisfy my need for an easy way to display a mathematic vector. I extended a LinearLayout and added an ArrayList for the values. Everytime the values change I call my custom method redraw() to add EditTexts to the LinearLayout. This way after adding a value, all existing EditTexts are added once again. How to I clear the LinearLayout or display a new LinearLayout?
Here some code:
public Vector(Context context, AttributeSet attrs) {
super(context, attrs);
setWillNotDraw(false);
LayoutInflater inflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
if (inflater != null) {
inflater.inflate(R.layout.vector, this);
}
}
public void redraw() {
for (Float value : getArray()) {
EditText edit = new EditText(getContext());
edit.setLayoutParams(new ViewGroup.LayoutParams(
ViewGroup.LayoutParams.WRAP_CONTENT,
ViewGroup.LayoutParams.FILL_PARENT));
edit.setText(value.toString());
((LinearLayout) findViewById(R.id.root)).addView(edit);
}
}
Upvotes: 0
Views: 87
Reputation: 2491
You can remove all views by using ((LinearLayout) findViewById(R.id.root)).removeAllViews()
.
But why do you want to add all the edit text all over again if you can set the new values to the existing edit text views and add new view only if you still need to.
I didn't fully understand you.
Upvotes: 1