I need to replace textview which is already define in xml layout file with dynamic textview created programmatically in my Activity class file.
Asked
Active
Viewed 208 times
0
-
[mcve] perhaps? – Shark Jul 11 '18 at 12:15
-
Why do you want to replace a `textView`? Please elaborate. – tahsinRupam Jul 11 '18 at 12:15
-
why do you want to replace the TextView? Why not replace the text or any of its properties instead? – Udit Jul 11 '18 at 12:15
-
@Udit https://stackoverflow.com/questions/51190630/how-to-create-customized-text-input-layout-like-attached-design/51191166?noredirect=1#comment89366398_51191166 i need to make a design like this,I try to combine image and text in a single drawable but i can't able to do that,so i try to replace textview with my custom textview. – Raj Jul 11 '18 at 12:17
2 Answers
0
You don't need replace it, just get the particular properties from textView
(from Java) and set them on text_view
(from XML).
For example:
text_view.setText(textView.getText().toString())
text_view.setColor(textView.getColor())
...
text_view.setAnything(textView.getAnything())
Maybe it helpfull to you

Abner Escócio
- 2,697
- 2
- 17
- 36
-
-
1
-
-
Guys can you help me out to design this layout https://stackoverflow.com/questions/51190630/how-to-create-customized-text-input-layout-like-attached-design/51191166?noredirect=1#comment89366398_51191166 – Raj Jul 11 '18 at 12:22
-
I'm go try simule a result for you. Wait few minutes. Android Studio is openig... – Abner Escócio Jul 11 '18 at 12:27
0
I didn't get why you would do this, but anyhow will layout the steps:
- get reference to the TextView containing ViewGroup
- call removeView with TextView Reference.
call addView with new TextView.
TextView old = (TextView) findViewById(R.id.old_text_view) LinearLayout layout = (LinearLayout) findViewById(R.id.container) TextView new = new TextView()
layout.removeView(old); layout.addView(new, position);

Udit
- 1,037
- 6
- 11