Reputation: 1871
I am trying to Display data received from the server in tabs format as shown below
The below code is in a for loop
TableRow.LayoutParams lp = new TableRow.LayoutParams(TableRow.LayoutParams.WRAP_CONTENT);
row.setLayoutParams(lp);
TextView textview1 = new TextView(this);
textview1.setText(received.getData(i+1,1));
TextView textview2 = new TextView(this);
textview2.setText(received.getData(i+1,2));
TextView textview3 = new TextView(this);
textview3.setText(received.getData(i+1,3));
TextView textview4 = new TextView(this);
row.addView(textview1);
row.addView(textview2);
row.addView(textview3);
row.addView(textview4);
tabLayout.addView(row,i);
I am trying to add data items like this. i have to make the alignment of the data items similar. The width of each item should be 89dp. I am not sure how to achieve this. Can anyone help me with the code to include the 89dp width in each TextViews
.
And also in addition how can I set color to single TextView
?
I tried the following code but it didnt set any color to that field.
textview4.setTextColor(getResources().getColor(R.color.colorPrimary));
Upvotes: 0
Views: 34
Reputation: 3068
You can simply call
textview4.setWidth(int here);
And for setting the text color are you sure R.color.colorPrimary is the correct color?
try:
textview4.setTextColor(Color.parseColor("#ff0000"));
this will make it red for testing to see if it changes.
Upvotes: 1