I have a linear layout which contains multiple widgets. I want to populate it using an ArrayList. I don't want to use use a listview because it didn't work in scrollview.
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="10" >
<TextView
android:id="#+id/xxxx"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="2"
android:gravity="top|left"
/>
<TextView
android:id="#+id/tv_xxx"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="4"
android:text="jshadb" />
<TextView
android:id="#+id/tv_xxx"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="2"
android:text="464.89" />
<EditText
android:id="#+id/et_xxxx"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="2"
android:hint=""
android:ems="10"
android:inputType="number" />
</LinearLayout>
Below the way
LayoutInflater linf = (LayoutInflater) getApplicationContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
linf = LayoutInflater.from(YourActivity.this);
//Linear Layout on you want to add inflated View
LinearLayout tbl_layout=(LinearLayout)findViewById(R.id.Layoutid);
for (int i = 0; i < arrayList.size(); i++) {
View v = linf.inflate(R.layout.YourLinearLayout, null);//Pass your lineraLayout
((TextView) v.findViewById(R.id.xxxx)).setText("textS");
tbl_layout.addView(v);
}
Related
data_shifted_down
Im creating an android project(java) that pulls data from server and places that data into a table so I have to create a table programmatically. I followed a few examples here but for every column in row its being shifted down...
I attached a pic.
activity_main.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TableLayout
android:id="#+id/details_table"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:layout_marginTop="10dp"
android:paddingLeft="5dp"
android:paddingRight="5dp"
>
<TableRow>
<TextView
android:text="User"
android:layout_width="match_parent"
android:layout_column="0"
android:layout_weight="1"
android:textSize="50px"
android:textColor="#color/black" />
<TextView
android:text="Store"
android:layout_width="match_parent"
android:layout_column="1"
android:layout_weight="1"
android:textSize="50px"
android:textColor="#color/black" />
<TextView
android:text="Item"
android:layout_width="match_parent"
android:layout_column="2"
android:layout_weight="1"
android:textSize="50px"
android:textColor="#color/black" />
<TextView
android:text="QTY"
android:layout_width="match_parent"
android:layout_column="3"
android:layout_weight="1"
android:textSize="50px"
android:textColor="#color/black"
/>
</TableRow>
</TableLayout >
</LinearLayout>
table_row.xml:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="match_parent"
android:layout_width="match_parent">
<TableRow
android:id="#+id/tr"
android:layout_height="match_parent"
android:layout_width="match_parent">
<TextView
android:id="#+id/tableCell1"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:layout_column="0"
android:layout_weight="1"
android:textColor="#color/black"
android:textSize="20dp" />
<TextView
android:id="#+id/tableCell2"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:layout_column="1"
android:layout_toRightOf="#+id/tableCell1"
android:layout_weight="1"
android:textColor="#color/black"
android:textSize="20dp" />
<TextView
android:id="#+id/tableCell3"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_column="2"
android:layout_toRightOf="#+id/tableCell2"
android:layout_weight="1"
android:textColor="#color/black"
android:textSize="20dp" />
<TextView
android:id="#+id/tableCell4"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_column="3"
android:layout_toRightOf="#+id/tableCell3"
android:layout_weight="1"
android:textColor="#color/black"
android:textSize="20dp" />
</TableRow>
</RelativeLayout>
MainActivity.java where it iterates through the data to add to TableRow then add that TableRow into TableLayout:
for (int c = 0; c < a.length; c++) {
final TableLayout detailsTable = (TableLayout) findViewById(R.id.details_table);
View v=getLayoutInflater().inflate(R.layout.tablerow, null);
TableRow tableRow = (TableRow) v.findViewById(R.id.tr);
detailsTable.setStretchAllColumns(true);
TextView tv = null;
switch (c) {
case 0:
tv = (TextView) tableRow.findViewById(R.id.tableCell1);
break;
case 1:
tv = (TextView) tableRow.findViewById(R.id.tableCell2);
break;
case 2:
tv = (TextView) tableRow.findViewById(R.id.tableCell3);
break;
case 3:
tv = (TextView) tableRow.findViewById(R.id.tableCell4);
break;
}
tableRow.setGravity(Gravity.CENTER_HORIZONTAL);
tv.setText(a[c]);
tv.setBackgroundColor(Color.parseColor("#f8f8f8"));
tv.setLayoutParams(new
TableRow.LayoutParams(TableRow.LayoutParams.WRAP_CONTENT,
TableRow.LayoutParams.MATCH_PARENT));
//new Log("here: ", Integer.toString(tv.getId()));
//Add row to the table
if(tableRow.getParent() !=null){
((ViewGroup)tableRow.getParent()).removeView(tableRow);
}
detailsTable.addView(tableRow);
Tried every solution on the site. Changed to RelativeLayout no luck. Tried gravity and every other attribe...
Looks a horrible way to try and do it but your problem is you are inflating a new tablerow for each item of data with:-
View v=getLayoutInflater().inflate(R.layout.tablerow, null);
who's parent is null
therefore:-
if(tableRow.getParent() !=null){ ((ViewGroup)tableRow.getParent()).removeView(tableRow); }
won't remove a view (not that you should be removing a view)
not tested but something like this might work but for only where a has 4 data items (because you switch statement won't work for anything longer - could also use modulus calculation for that)
View v;
for (int c = 0; c < a.length; c++) {
// Every 4th data item (remainder is zero) e.g. 0,4,8,etc
if ((c%4) == 0) {
// inflate the view
v=getLayoutInflater().inflate(R.layout.tablerow, null);
}
// Rest of your code
....
//Add row to the table
if ((c%4) == 0) {
detailsTable.addView(tableRow);
}
}
I have downloaded a library from Github - https://github.com/riyagayasen/Android_accordion_view and added it as a module to my project.
I want to change the layout of the view, because the default one doesn't quite suit my design. By default it looks like this: https://pp.userapi.com/c855132/v855132038/18192/AJnXb6Z7l4c.jpg; I want it look like this: https://pp.userapi.com/c855132/v855132038/18178/VyKEhn6ERuk.jpg; but all i have achieved is this: https://pp.userapi.com/c848416/v848416709/1602db/3JjKU9eMj0g.jpg.
It is clear that I have to change the layout of the AccordionView.
The path to the layout XML is Android_accordion_view/easyaccordion/src/main/res/layout/accordion.xml
I am sure that AccordionView uses exactly this layout because there is a method in AccordionView.java that inflates this XML as a layout:
private void initializeViews(Context context) {
inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
//here it happens
LinearLayout accordionLayout = (LinearLayout) inflater.inflate(R.layout.accordion, null);
partition = accordionLayout.findViewById(R.id.partition);
heading = (TextView) accordionLayout.findViewById(R.id.heading);
paragraph = (RelativeLayout) accordionLayout.findViewById(R.id.paragraph_layout);
dropdownImage = (ImageView) accordionLayout.findViewById(R.id.dropdown_image);
dropupImage = (ImageView) accordionLayout.findViewById(R.id.dropup_image);
headingLayout = (LinearLayout) accordionLayout.findViewById(R.id.heading_layout);
paragraph.removeAllViews();
int i;
children = new View[getChildCount()];
for (i = 0; i < getChildCount(); i++) {
children[i] = getChildAt(i);
}
removeAllViews();
for (i = 0; i < children.length; i++) {
paragraph.addView(children[i]);
}
paragraphBottomMargin = ((LinearLayout.LayoutParams) paragraph.getLayoutParams()).bottomMargin;
paragraphTopMargin = ((LinearLayout.LayoutParams) paragraph.getLayoutParams()).topMargin;
addView(accordionLayout);
}
The problem is that if I change accordion.xml, nothing actually changes when I add the AccordionView to my fragment's layout, and that's super weird.
I assume that I have somehing wrong in Gradle dependences or somewhere near it, but I can't figure it out.
That is the xml that I want to change the default layout to.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="match_parent"
android:background="#drawable/accordion_background"
android:layout_height="wrap_content">
<android.support.constraint.ConstraintLayout
android:id="#+id/heading_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<CheckBox
android:id="#+id/favourite_checkBox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginLeft="8dp"
android:layout_marginTop="2dp"
android:layout_marginEnd="8dp"
android:layout_marginRight="8dp"
android:button="#drawable/star_checkbox"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintStart_toEndOf="#+id/heading"
app:layout_constraintTop_toTopOf="parent" />
<ImageView
android:id="#+id/dropup_image"
android:layout_width="34dp"
android:layout_height="26dp"
android:layout_marginTop="2dp"
android:scaleType="fitCenter"
android:src="#drawable/ic_arrow_up"
android:visibility="gone"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="#+id/favourite_checkBox"
app:layout_constraintStart_toStartOf="#+id/favourite_checkBox"
app:layout_constraintTop_toBottomOf="#+id/favourite_checkBox" />
<ImageView
android:id="#+id/dropdown_image"
android:layout_width="0dp"
android:layout_height="18dp"
android:layout_marginTop="2dp"
android:layout_marginBottom="2dp"
android:scaleType="fitCenter"
android:src="#drawable/ic_arrow_down"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="#+id/favourite_checkBox"
app:layout_constraintStart_toStartOf="#+id/favourite_checkBox"
app:layout_constraintTop_toBottomOf="#+id/favourite_checkBox" />
<TextView
android:id="#+id/heading"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:layout_marginStart="8dp"
android:layout_marginLeft="8dp"
android:text="Title"
android:textStyle="bold"
android:visibility="visible"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</android.support.constraint.ConstraintLayout>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:id="#+id/partition"
android:background="#android:color/darker_gray" />
<RelativeLayout
android:id="#+id/paragraph_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:animateLayoutChanges="true"
android:orientation="vertical"
android:paddingTop="10dp"
android:visibility="visible"
tools:visibility="visible">
</RelativeLayout>
</LinearLayout>
Yes, I understand that the heading layout is LinearLayout by default, but even if I change the dropdown icon size in the default layout, it stays the same when I use the view.
So my question is: how can I make the layout above appear when I use the view?
I will provide any of my code by your request.
Thank you.
I have created a gridlayout with width=3 and height =2. i placed 6 views in each grid element with ids as view1,view2,view3,view4,view5 and view 6. now how to place buttons on each view programmatically?
View child1,child2,child3,child4,child5,child6;
child1=(View)view.findViewById(R.id.view1);
child2=(View)view.findViewById(R.id.view2);
child3=(View)view.findViewById(R.id.view3);
child4=(View)view.findViewById(R.id.view4);
child5=(View)view.findViewById(R.id.view5);
child6=(View)view.findViewById(R.id.view6);
and finally to place dynamic buttons i used the code as below.
child1 = this.getActivity().getLayoutInflater().inflate(R.layout.video,null);
video = (Button)child1.findViewById(R.id.button);
this continues for child2,3 etc.video is an xml layout with a button id as button.
the layout is as follows
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_height="match_parent"
android:orientation="vertical"
android:weightSum="1">
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#484848"
android:layout_weight=".1">
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/imb1"
android:layout_weight=".07"
android:layout_marginBottom="7.5dp"
android:textColor="#ffffff"
android:src="#drawable/back"
android:adjustViewBounds="false"
android:background="#484848" />
<ImageView
android:id="#+id/imageView"
android:layout_width="wrap_content"
android:layout_height="50dp"
android:layout_gravity="center_vertical"
android:background="#484848"
android:src="#drawable/medilearn1"
android:layout_weight=".15"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Dashboard"
android:id="#+id/textView3"
android:layout_gravity="center"
android:textColor="#fbfbfb"
android:textAlignment="viewStart"
android:layout_marginLeft="20dp"
android:layout_weight="0.67" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Restart"
android:id="#+id/button3"
android:layout_weight=".07"
android:background="#d86018"
android:textColor="#ffffff"
android:layout_marginTop="7.5dp"
android:layout_marginBottom="7.5dp"
android:layout_marginRight="7.5dp" />
</LinearLayout>
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#d8d8d8"
android:layout_weight=".9">
<SearchView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/searchView"
android:background="#ffffff"
android:queryHint="search"
android:layout_gravity="center_horizontal" />
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fillViewport="true"
android:background="#d8d8d8">
<GridLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:columnCount="3"
android:rowCount="2"
android:id="#+id/gridView">
<View
android:layout_width="0dp"
android:layout_height="200dp"
android:layout_columnWeight="1"
android:id="#+id/view1" />
<View
android:layout_width="0dp"
android:layout_height="200dp"
android:layout_columnWeight="1"
android:id="#+id/view2" />
<View
android:layout_width="0dp"
android:layout_height="200dp"
android:layout_columnWeight="1"
android:id="#+id/view3" />
<View
android:layout_width="0dp"
android:layout_height="200dp"
android:layout_columnWeight="1"
android:id="#+id/view4" />
<View
android:layout_width="0dp"
android:layout_height="200dp"
android:layout_columnWeight="1"
android:id="#+id/view5" />
<View
android:layout_width="0dp"
android:layout_height="200dp"
android:layout_columnWeight="1"
android:id="#+id/view6" />
</GridLayout>
</ScrollView>
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#484848"
android:layout_weight=".1">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Version:1.0"
android:id="#+id/textView6"
android:layout_gravity="center"
android:textColor="#fbfbfb"
android:textAlignment="viewStart"
android:layout_marginLeft="20dp" />
</LinearLayout>
</LinearLayout>
This is my layout.
I found the solution. I declared linearlayout in each grid with hight and width as my wish and called child with addView().so,
LinearLayout lay1=(LinearLayout)view.findViewById(R.id.layout1);
and then
lay1.addView(child1);
You can add a Button to your view like this:
Button btn = new Button();
btn.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
btn.setId(1);
btn.setText("ButtonText");
yourView.addView(btn);
If you want it to fill your whole view, replace LayoutParams.WRAP_CONTENT with LayoutParams.MATCH_PARENT.
just set adapter for your GridView
MyGridAdapter csAdapter = new MyGridAdapter();
csGridView.setAdapter(csAdapter);
csGridView.setOnItemClickListener(gridItemClicked);
and adapter code is
public AdapterView.OnItemClickListener gridItemClicked = new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
//your code
}
};
Update:
Based on the layout you posted there are two options you can pursue:
Create the layout in your xml file: you could just replace the View tags with Button tags if your layout is static and will always require those buttons.
Create the layout dynamically: for this you don't need the View tags inside your layout as those will be created programmatically, so you can remove those. Then do the following for every Button you want to create (I'm assuming the layout containing the buttons is called video.xml):
View child = this.getActivity().getLayoutInflater().inflate(R.layout.video,null);
GridLayout.LayoutParams params = new GridLayout.LayoutParams();
// set the row number this child is located in
params.rowSpec = GridLayout.spec(rowNum, 1);
// set the column number this child is located in
params.columnSpec = GridLayout.spec(colNum, 1);
child.setLayoutParams(params);
grid.addView(child);
Also, please note that a View cannot have a child View, only layouts extending ViewGroup (e.g. FrameLayout, GridLayout, ...) can have child Views!
The best way to inflate the View in your case is the following code:
GridLayout grid = view.findViewById(R.id.grid); // get the grid layout
// ...
child1 = this.getActivity().getLayoutInflater().inflate(R.layout.video, grid, true);
video = (Button)child1.findViewById(R.id.button);
By providing the parent (grid), the LayoutInflator will take care of properly inflating the requested resource into the view hierarchy, the true attaches the inflated layout to the root layout.
Also check the API docs for this:
inflate(int resource, ViewGroup root, boolean attachToRoot):
Inflate a new view hierarchy from the specified xml resource.
I am trying to add a TextInputLayout with an EditText based on a number that the user selects from a Spinner. I already have the TextInputLayout attributes defined in XML and was hoping to simple just add them programmatically based on the number that the user selects from the spinner:
XML:
<FrameLayout
android:background="#drawable/image_border"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight=".525">
<Button
android:id="#+id/add_image_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="Click to Add Image" />
</FrameLayout>
<LinearLayout
android:orientation="vertical"
android:padding="4dp"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight=".475">
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<EditText
android:id="#+id/create_poll_question_editText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:imeOptions="actionDone"
android:singleLine="true"
android:hint="#string/create_poll_question" />
</android.support.design.widget.TextInputLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="#+id/how_many_answers_textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/how_many_answers_text"
android:textColor="#color/black"
android:textSize="16sp" />
<Spinner
android:id="#+id/number_of_answers_spinner"
android:layout_width="wrap_content"
android:layout_gravity="bottom"
android:layout_height="24dp"
android:background="#android:drawable/btn_dropdown" />
</LinearLayout>
<!--Want to Add Programatically -->
<android.support.design.widget.TextInputLayout
android:id="#+id/create_poll_answer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<EditText
android:id="#+id/create_poll_answer_editText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:imeOptions="actionDone"
android:singleLine="true"
/>
</android.support.design.widget.TextInputLayout>
</LinearLayout>
Here is the code I am currently using, but it does not add dynamically based on the view I already created:
public class YourItemSelectedListener implements AdapterView.OnItemSelectedListener {
public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) {
String selected = parent.getItemAtPosition(pos).toString();
Toast.makeText(getActivity().getApplicationContext(), selected, Toast.LENGTH_SHORT).show();
for (int i = 0; i < Integer.parseInt(selected); i++) {
ViewGroup layout = (ViewGroup) mRootView.findViewById(R.id.create_poll_linearlayout);
EditText editText = new EditText(getActivity());
editText.setHint("Poll Answer");
LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
editText.setLayoutParams(layoutParams);
TextInputLayout newAnswer = new TextInputLayout(getActivity());
newAnswer.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT));
newAnswer.addView(editText, layoutParams);
layout.addView(newAnswer);
}
}
Easiest way to do such dynamic injections of view is to use ButterKnife library by JakeWharton
http://jakewharton.github.io/butterknife/
You can use it like in your activity's declaration part:
#BindView(R.id.title) TextInputLayout textInputLayout;
Then bind it inside onCreate() like:
ButterKnife.bind(this);
This will roughly be equivalent to inflating and finding the view by id.
Moreover, the library helps to dynamically set drawables,etc. with ease as well
Add
android:id="#+id/create_poll_linearlayout"
to your root LinearLayout.
Im new to Android and I'm trying to add a TableRow, which I already made with xml, to a TableLayout programmatically. I'm getting Force Closes, most are NullPointerExcpetions.
Here's my java class
public class DayFragment extends Fragment {
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.subjects_list, container, false);
TableLayout tl = (TableLayout) view.findViewById(R.id.tl);
TableRow tr = (TableRow) view.findViewById(R.id.tr_row);
tl.addView(tr); //not working, obviously im missing something
//xml parsing stuff
return view;
}
}
This is my layout with the TableLayout:
<?xml version="1.0" encoding="utf-8"?>
<HorizontalScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/horizontalScrollView1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:paddingTop="5dp" >
<ScrollView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fillViewport="true"
android:orientation="vertical" >
<TableLayout
android:id="#+id/tl"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<include
android:id="#+id/header"
layout="#layout/table_header" />
<include android:id="#+id/h_divider"
layout="#layout/horizontal_divider"/>
</TableLayout>
</ScrollView>
</HorizontalScrollView>
And the TableRow:
<?xml version="1.0" encoding="utf-8"?>
<TableRow xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/tr_row"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TextView
android:id="#+id/tv_hour"
android:layout_weight="1"
android:gravity="center"
android:padding="8dp"
android:textSize="15sp"
android:textStyle="bold" />
<View
android:layout_weight="1"
android:background="#drawable/vertical_cell_divider" />
<TextView
android:id="#+id/tv_subject"
android:layout_weight="1"
android:gravity="left"
android:padding="8dp"
android:textSize="18sp" />
<View
android:layout_weight="1"
android:background="#drawable/vertical_cell_divider" />
<TextView
android:id="#+id/tv_start"
android:layout_weight="1"
android:gravity="left"
android:padding="8dp"
android:textSize="18sp" />
<TextView
android:id="#+id/tv_bar"
android:layout_weight="1"
android:gravity="left"
android:textSize="18sp" />
<TextView
android:id="#+id/tv_end"
android:layout_weight="1"
android:gravity="left"
android:padding="8dp"
android:textSize="18sp" />
</TableRow>
I tried lots of different ways to achieve it but still nothing.
Replace code:
TableRow tr = (TableRow) view.findViewById(R.id.tr_row);
tl.addView(tr); //not working, obviously im missing something
with
View tr = inflater.inflate(R.layout.table_row_layout, null,false);
tl.addView(tr); //not working, obviously im missing something