I want to build an app that will generate several textview which will all fit in the designated layout. but once the line is full instead of continue in new line it not show the rest of the textviews
my MainActivity.java:
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ArrayList<String> urls=new ArrayList<String>(); //to read each line
LinearLayout linearLayout = (LinearLayout) findViewById(R.id.sell);
// Add textview 1
for (int i=0;i<10;i++){
LinearLayout.LayoutParams layoutParams1 = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
layoutParams1.setMargins(10, 10, 10, 10);
TextView textView1 = new TextView(this);
textView1.setLayoutParams(layoutParams1);
textView1.setText("TextView1\n2");
textView1.setBackgroundColor(0xFF3EB427); // hex color 0xAARRGGBB
textView1.setPadding(10, 10, 10, 10);// in pixels (left, top, right, bottom)
linearLayout.addView(textView1);
}
LinearLayout linearLayout2 = (LinearLayout) findViewById(R.id.buy);
LinearLayout.LayoutParams layoutParams2 = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
for (int i=0;i<2;i++){
layoutParams2.setMargins(10, 10, 10, 10);
TextView textView1 = new TextView(this);
textView1.setLayoutParams(layoutParams2);
textView1.setText("TextView2");
textView1.setBackgroundColor(0xFFB60612); // hex color 0xAARRGGBB
textView1.setPadding(20, 20, 20, 20);// in pixels (left, top, right, bottom)
linearLayout2.addView(textView1);
}
}
}
my xml:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:background="#ffffff"
android:layout_height="match_parent"
android:id="@+id/mymain"
android:orientation="vertical"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.example.ohad.tradertracker.MainActivity"
android:weightSum="1">
<LinearLayout
android:id="@+id/stats"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="101dp">
</LinearLayout>
<LinearLayout
android:id="@+id/sell"
android:layout_weight=".5"
android:fillViewport="true"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent">
</LinearLayout>
How can i generate unknown amount of textview and use all layout size???