-
Notifications
You must be signed in to change notification settings - Fork 239
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add own layout inflater on getView #30
Comments
Hi @agapaymarlo, to get shure that I understood you correctly: You want to create a TableView with a custom Cell layout. Is this what you are trying to achive? Best regards, |
hi @ISchwarz23 no, i just want to implement it on the whole row, (inflate). right now, we can change only the colors per row.. but is there any way that i can inflate my xml layout? i try to overwrite the public final View getView() on my own adapter, but i cant, because its final. thanks in advance |
I'm not sure if I got you correctly, but if you want to have an example on how to inflate a custom layout in the If you want to set a background color for a specfic cell, simply set the color as the background of the view in the specific cell. I adapted the @Override
public View getCellView(final int rowIndex, final int columnIndex, final ViewGroup parentView) {
final Car car = getRowData(rowIndex);
View renderedView = null;
switch (columnIndex) {
case 0:
...
case 3:
renderedView = renderPrice(car);
break;
}
return renderedView;
}
private View renderPrice(final Car car) {
final String priceString = PRICE_FORMATTER.format(car.getPrice()) + " €";
final TextView textView = new TextView(getContext());
textView.setText(priceString);
textView.setPadding(20, 40, 20, 40);
textView.setTextSize(TEXT_SIZE);
if (car.getPrice() < 50000) {
textView.setBackgroundColor(0xFF2E7D32);
} else if (car.getPrice() > 100000) {
textView.setBackgroundColor(0xFFC62828);
}
return textView;
} |
I think you just want to replace: |
But if you replace the |
I was thinking something like protected LinearLayout createRow(rowIndex) {
return new new LinearLayout(getContext());
} Subclasses could override it to create their own and set any other props or inflate it from xml, it would still have to return a LinearLayout. Right now I can get around by just doing my extra stuff in getView() something like this: if (columnIndex == 0 && rowHasBorder(data)) { //only need to do this once per row
parentView.setBackground(getResources().getDrawable(R.drawable.bottom_border ));
} |
So, you want something like a TableDataRowColorizer but instead of giving a color you want to have the possibility to give a drawable? |
Since version 2.1.0 the No you can achive your aimed behaviour: public class BottomBorderBackgroundProvider implements TableDataRowBackgroundProvider<MyData> {
@Override
public Drawable getRowBackground(final int rowIndex, final MyData data) {
if( hasBottomBorder( data ) ) {
return getResources().getDrawable(R.drawable.bottom_border);
} else {
return getResources().getDrawable(R.drawable.default_background);
}
}
private boolean hasBottomBorder(final MyData data) {
// your logic goes here
}
} and set this to your table: tableView.setDataRowBackgroundProvider( new BottomBorderBackgroundProvider() ); |
In previous version of the library I can easily overload the Currently I am reverting back to old version of the library that is 1.0.1 which lets the |
Hi Ahmad, I really do not like to remove the final from the getView method as this would allow miss-use of the TableView. There has to be a very good reason for removing it. Best regards, |
Reason is pretty valid, I want to have a click listener on the whole row. In a rare case I also want to expand the row to show more information on long click listener. If you can provide some other click listener api or interface and favorably long click listener too,with index and row item access, than I can update to version two. Usecase. We don't always use table view to just show information but sometime we also want to act on that row, clicking columns can be difficult on little screen. In my use case I am showing a list of jobs to be completed in a project. Job status, name and description is in table row, now on clicking the job (row) user can go to a job detail page to act on the job and by long clicking users can expand row, to view some buttons below it, to change the job status quickly without details. So depending on the item case I would override the (row) view to make it expandable, or clickable or not. |
Hi Ahmad, as you said, as the screen is pretty small, I don't know if adding buttons inside the table is the best solution. Never the less, the listeners for clicking on data items have a look at 'TableDataClickListener' or for long clicks see 'TableDataLongClickListener'. There are a lot more listeners available. Best regards, |
Thanks, I did not notice that, I think added recently. One problem is solved yet the expandable view or custom view problem not... :-) |
The click listener was always there, only the long click listener was introduced in 2.2.0. |
I work for DgHeating, UK and they really like the table view :-), I have already updated the tableView version to latest, That will be good if you could guide me to how can I expand row view on long click. Another thing I want to know is how can I give |
What kind of TableDataAdapter do u use? The SimpleTableDataAdapter or a custom one? |
Yes a simple TableDataAdapter with extended SortableTableView. Uploaded for you TableDataAdapter, TableView. |
So, the height of a row is defined by the cell with the biggest height. So by defining your cells you define the rows passively. It's the same for the padding. You can not define the padding for the full row, but for the cells inside your row. I will create an ExpandableTableDataAdapter for you at the weekend. |
Have a look at the ExpandableTableDataAdapter. Just make your adapter extend the ExpandableTableDataAdapter and implement the |
i cant implement my public View getView on my own inside my adapter to inflate my own layout for the rows is there any way that i can make it? thanks
The text was updated successfully, but these errors were encountered: