简体   繁体   中英

How to overwrite previous TextView and EditText in android

I have a spinner with the values = {4,5,6,7} , initially spinner selected value is set to 4 , therefore 4 TextViews and 4 EditTexts showing in the activity.

Now I want if the user select value 5 from the spinner then these previous 4 TextViews and EditTexts will overwrite with new 5 TextViews and 5 EditTexts . How can I do so ? any help?

  1. You can write your TextView and EditText as an item of RecyclerView and every time you can have as much items as you want. OR
  2. every time add TextView and EditText programmatically from the java code.

For this you can manage through loop like...

for( int i = 0; i < spinner.getSelectedItem(); i++)
{
TextView textView = new TextView(this);
textView.setText(textArray[i]);
linearLayout.addView(textView);
}

For create view one after another create programmatically layout like this:

LinearLayout linearLayout = new LinearLayout(this);
setContentView(linearLayout);
linearLayout.setOrientation(LinearLayout.VERTICAL)

Like this you can manage programmatically as per your need.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM