I want add a array of strings (will be TextView) into two LinearLayout dynamically, when idx even add in first LinearLayout, when odd the second.
I define three members in MainActivity:
LinearLayout first;
LinearLayout second;
LinearLayout now;
and in the for loop of array of strings, do:
if(idx%2==0){
now=first;
}else{
now=second;
}
ViewGroup.LayoutParams lparams = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
TextView textView = new TextView(MainActivity.this);
textView.setLayoutParams(lparams);
textView.setText(strings[idx]);
now.addView(textView);
But all TextView go to the first LinearLayout, and the second LinearLayout is empty. Why? I am new in java and android development. Can anyone help? Thank you!