I want to set ID for a dynamically added textview in a loop. I found out that the only function they have is setId with int parameter. How can we set the ID with string, perhaps like this:
LinearLayout linearLayout = findViewById(R.id.linearLayout);
for(int i=0; i<10; i++) {
TextView textView = new TextView(this);
textView.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT));
textView.setText("Text Number "+i);
textView.setId("@+id/myTextView"+i); // => Is this possible? This will cause error because setId needs INT type parameter.
linearLayout.addView(textView);
}
I don't want to use resource file because it's not dynamic. Is it possible?