imageview and listview - java

I have a listview with a ImageView that appears when i click on one of the elements of the list.
public void onItemClick(AdapterView<?> parent, View view, int position,
long id) {
ImageView icon = (ImageView) view.findViewById(R.id.icon);
icon.setImageResource(R.drawable.valider);
choiceDialog(view);
}
My layout file for the rows
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="1dip">
<ImageView
android:id="#+id/icon"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_marginRight="6dip"
/>
<LinearLayout
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="fill_parent">
<TextView
android:id="#+id/nom"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:singleLine="true"
android:ellipsize="marquee"
android:textSize="15px"
android:textStyle="bold"
android:typeface="serif" />
/>
<TextView
android:id="#+id/date_heure"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:singleLine="true"
android:ellipsize="marquee"
android:textSize="15px"
android:textStyle="bold"
android:typeface="serif" />
<TextView
android:id="#+id/adresse"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:ellipsize="marquee"
android:textSize="15px"
android:textStyle="bold"
android:typeface="serif" />
</LinearLayout>
</LinearLayout>
The problem is that if I delete an element from the list, the ImageViewe is transferred to the element above whereas it was not clicked at first.
I tried to remove the image when the item is removed like this:
resolver.delete(DB_RDVUtils.CONTENT_URI, ligne,null);
ImageView icon = (ImageView) item.findViewById(R.id.icon);
icon.setImageResource(0);
but in this case, it removes all of the imagesview in the list
How to fix this bug please
Thank you very much

After removing an element from the list, remember to call Adapter.notifyDataSetchanged() so the ListView updates correctly.

Have you tried this?
resolver.delete(DB_RDVUtils.CONTENT_URI, ligne,null);
ImageView icon = (ImageView) item.findViewById(R.id.icon);
icon. invalidateDrawable(icon.getDrawable());

Related

OnClickListener not getting invoked in recycler view

I am using a SwipeRevealLayout for a single item in a recyclerview and also want to attach an OnClickListener on it. This is my xml file of layout of a single item:
<com.chauthai.swipereveallayout.SwipeRevealLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:mode="normal"
app:dragEdge="left"
android:clickable="true">
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/colorPrimary"
android:padding="8dp"
android:gravity="center_vertical"
android:clickable="false">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_archive"
android:clickable="false"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Archive"
android:id="#+id/id_text_archive"
android:textSize="24sp"
android:textColor="#color/colorTextLight"
android:clickable="false"/>
</LinearLayout>
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#android:color/white"
android:padding="8dp"
android:clickable="false">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Test Chat Name"
android:textSize="24sp"
android:textColor="#android:color/black"
android:id="#+id/id_text_chat_head"
android:clickable="false"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Test Chat Name"
android:textSize="18sp"
android:textColor="#color/colorChatroomSubTitle"
android:id="#+id/id_text_chat_sub_head"
android:clickable="false"/>
</LinearLayout>
</com.chauthai.swipereveallayout.SwipeRevealLayout>
Here is my viewholder code:
public class ChatHolder extends RecyclerView.ViewHolder implements View.OnClickListener{
#BindView(R.id.id_text_chat_head)
TextView mChatHead;
#BindView(R.id.id_text_chat_sub_head)
TextView mChatSubHead;
#BindView(R.id.id_text_archive)
TextView mTextArchive;
private View mView;
private AnonymousReport mAnonymousReport;
public ChatHolder(#NonNull View itemView) {
super(itemView);
mView = itemView;
ButterKnife.bind(this, itemView);
itemView.setOnClickListener(this);
}
public SwipeRevealLayout getSwipeRevealLayout() {
return ((SwipeRevealLayout) mView);
}
public void bindView(AnonymousReport report) {
mAnonymousReport = report;
mChatHead.setText(report.getSubject());
mChatSubHead.setText(report.getAnonTypeText(mContext));
mTextArchive.setText(isArchived ? "Unarchive" : "Archive");
}
#Override
public void onClick(View v) {
startActivity(AnonymousReportDetailsActivity.newIntent(mContext, mAnonymousReport));
}
}
I have tried attaching onActionEvent and that works but I need t get OnClickListner to work.
Can someone please help me figure out the issue? Thanks
From RecyclerView.ViewHolder documentation:
A ViewHolder describes an item view and metadata about its place within the RecyclerView.
RecyclerView.Adapter implementations should subclass ViewHolder and add fields for caching potentially expensive findViewById(int) results.
ViewHolder custom implementations are mostly used for caching purposes which means that the line below has no effect because you are setting the listener to a data store container.
itemView.setOnClickListener(this);
The solution is to set the listener to the actual itemView (probably just before you call ChatHolder(itemView)).
Unfortunately I cannot be sure therefore please post the code for your custom recycler view.
So I solved the issue, got help from the official github Repo of SwipeRevealLayout.
Here's link to original post
Here's what it said:
You can set onClick for main layout and secondary layout, but you
can't set onClick for the whole swipeRevealLayout.
So I modified my code accordingly and it worked.
<com.chauthai.swipereveallayout.SwipeRevealLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:mode="normal"
app:dragEdge="left">
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/colorPrimary"
android:padding="8dp"
android:gravity="center_vertical"
android:id="#+id/id_chat_room_item"
android:clickable="true">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_archive"
android:clickable="false"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Archive"
android:id="#+id/id_text_archive"
android:textSize="24sp"
android:textColor="#color/colorTextLight"
android:clickable="false"/>
</LinearLayout>
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#android:color/white"
android:padding="8dp"
android:clickable="false">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Test Chat Name"
android:textSize="24sp"
android:textColor="#android:color/black"
android:id="#+id/id_text_chat_head"
android:clickable="false"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Test Chat Name"
android:textSize="18sp"
android:textColor="#color/colorChatroomSubTitle"
android:id="#+id/id_text_chat_sub_head"
android:clickable="false"/>
</LinearLayout>
</com.chauthai.swipereveallayout.SwipeRevealLayout>

how to place buttons in my custom view?

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.

How to find the ID of a dynamic UI element in android

I can make the dynamic UI without problems, but I don't know how to access the view with findviewbyid (R.id._____) I don't know what to put in the blank.
.java code
public class newList extends AppCompatActivity {
Button btnAddItem;
RelativeLayout layout;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_new_list);
// allows the creation of dynamic rows
btnAddItem = (Button) findViewById(R.id.addItem);
btnAddItem.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
LayoutInflater inflater = getLayoutInflater();
ViewGroup parent = (ViewGroup) findViewById(R.id.linearVert);
inflater.inflate(R.layout.rows, parent);
}
});
}
}
xml that is associated with the java file
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
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.app.shoppingbuddy.shoppingbuddy.newList">
<ScrollView
android:layout_width="fill_parent"
android:layout_height="300dp"
android:id="#+id/scrollView" >
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:id="#+id/linearVert">
</LinearLayout>
</ScrollView>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Subtotal"
android:id="#+id/subtotal"
android:textColor="#ffc800"
android:layout_above="#+id/tax"
android:layout_alignParentStart="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Tax"
android:id="#+id/tax"
android:textColor="#ee00ff"
android:layout_above="#+id/total"
android:layout_alignParentStart="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Total"
android:id="#+id/total"
android:textColor="#ff0000"
android:layout_alignParentBottom="true"
android:layout_alignParentStart="true"
android:layout_marginBottom="20dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:id="#+id/subtotalAmount"
android:layout_alignBottom="#+id/subtotal"
android:layout_alignEnd="#+id/scrollView"
android:textColor="#ffc800" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:id="#+id/taxAmount"
android:layout_above="#+id/total"
android:layout_alignParentEnd="true"
android:textColor="#ee00ff" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:id="#+id/totalAmount"
android:layout_alignBottom="#+id/total"
android:layout_alignEnd="#+id/taxAmount"
android:textColor="#ff0000" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Add Item"
android:id="#+id/addItem"
android:layout_above="#+id/subtotal"
android:layout_centerHorizontal="true"
android:layout_marginBottom="20dp" />
</RelativeLayout>
xml used to create rows
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:weightSum="1"
android:id="#+id/linearHor">
<ImageView
android:layout_width="40dp"
android:layout_height="40dp"
android:id="#+id/itemImage"
android:src="#drawable/box"
android:padding="5dp" />
<EditText
android:layout_width="109dp"
android:layout_height="wrap_content"
android:id="#+id/itemName"
android:hint="Name"
android:layout_weight="0.78" />
<EditText
android:layout_width="100dp"
android:layout_height="wrap_content"
android:inputType="number"
android:ems="10"
android:id="#+id/itemPrice"
android:hint="$ Price" />
</LinearLayout>
</LinearLayout>
There will be no unique R.id value at the activity level. For example, suppose the user taps the button 10 times, so you inflate the R.layout.rows layout 10 times. As a result, there will be 10 R.id.linearHor widgets, 10 R.id.itemPrice widgets, and so on.
Always call findViewById() on something that is guaranteed to give you a unique result. In this case — as with ListView, GridView, RecyclerView, etc. — you need to use other approaches to find the correct row View, then call findViewById() on that View to get at its child widgets.

Android tablelayout click listener for cell content

I have a 3x3 gridview with custom linearlayouts within. But I want something like this
layout and as I search on the internet it's not possible with gridview because of the column span. I used gridview because of the onClickListener method: when the user click on one of the grid cell, a new activity starts(not the same activity, so it's like a main menu). Is it possible to do in a TableLayout? So if I click on a cell even if it spanned can I call an onClick method? I've searched the web for some solutions, but all of what I've found is clicking on a tablerow(which is not good for me if there is 3 custom layouts in one row).
My layout for the TableLayout:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#android:color/background_light"
android:orientation="vertical" >
<ImageView
android:id="#+id/headerPicture"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:contentDescription="#string/imageString"
android:src="#drawable/bicaj" />
<TableLayout
android:id="#+id/mainGrid"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:numColumns="3" >
<TableRow
android:id="#+id/mainFirstRow"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="5dip" >
<LinearLayout
android:id="#+id/mainOnline"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<ImageView
android:id="#+id/mainIconOnline"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:contentDescription="#string/main_page_icon_descp" />
<TextView
android:id="#+id/mainTextOnline"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="12sp" />
</LinearLayout>
</TableRow>
.
.
.
.
</TableLayout>
</LinearLayout>
You can add clickListeners to the ImageView
.....
<LinearLayout
android:id="#+id/mainOnline"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<ImageView
android:id="#+id/mainIconOnline"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:contentDescription="#string/main_page_icon_descp" />
......
And in your Activity
ImageView butt1 = (ImageView) findViewById(R.id.mainIconOnline);
butt1.setOnClickListener(this);
#Override
public void onClick(View v) {
if (v.getId() == R.id.mainIconOnline) {
Intent i = new Intent(this, SecondActivityclass);
startActivity(i);
}
}
This should work

How to add TableRow from xml to TableLayout programmatically?

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

Categories