Storing seekbar values after drag drop process end in ListView - android-listview

I have listView with drag drop functionality. I'm using ListView with custom layout- I have SeekBar and TextView in custom ListView layout. When I drag and drop each ListView items after changing SeekBar value, TextView is moving and SeekBar value is not moving.
It may be caused by Adapter. So I've share my adapter codes.
https://gist.github.com/salihyalcin/38e320726e3ab8346c50
Thanks in advance
EDIT --- My ListItem Class
class ListItem {
String textdata;
public ListItem(String textdata) {
this.textdata = textdata;
}
public boolean equals(Object o) {
ListItem ndListItemObject = (ListItem) o;
return this.textdata.equalsIgnoreCase(ndListItemObject.textdata);
}
}
** My ListView looks like image below
** Change the SeekBar value of Layer1
** Drag-Drop Layer1 and Layer2
** Layer1 and Layer2 moved but SeekBar values stay same place, they didn't moved.

I think I have an idea. First, your post is missing code snippet of the definition of NavigationDrawerFragment.ListItem class, could be helpful. I do remember that you call method swapElements in DynamicListView but other readers probably don't need to know it.
My suggestion is to save the progress value into the ListItem class, sample code below. We will depend on swapElements() to swap the 2 ListItem objects properly, along with the progress and text (layers in your case).
EDIT, code suggestion for ListItem class:
class ListItem {
String textdata;
int seekBarValue;
public ListItem(String textdata) {
this.textdata = textdata;
}
public ListItem(String textdata, int seekBarValue) {
this.textdata = textdata;
this.seekBarValue = seekBarValue;
}
...
Notes for ListItem code:
Added seekBarValue as a public data member, and another ListItem constructor for the caller's convenience.
This is what I meant by add another data member to this class.
Code snippet suggestion for the Adapter:
holder.mSeekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
#Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
final NavigationDrawerFragment.ListItem item = myItems.get(position);
View view = (View) seekBar.getParent();
if (view != null) {
holder.text.setText(progress + "%");
item.seekBarValue = progress;
Notes:
Added code line ...item = myItems.get(position); to get the correct item in the ArrayList.
Set the progress to item.seekBarValue
You may remove these codes below unless you plan on using it, of course:
holder.mSeekBar.getTag();
holder.text.getTag();
mar.get(1,progress);

Related

Textview resets to old value when scrolling up

I am creating a list view. I am populating the listview using custom adapter. In my listview there is a text view widget. When I reset the value of that text view it displays fine. Then, I scroll down to get new values into the listView. But when I scroll up the text view widget resets back to the old populated value.
How can I retain the new value set by me persistently?
Here is the code of my listview adapter class where I populate the values to my listview. I am clicking on imageview in the listview that fires the event to set new text value to the text view widget in the list view.
private class MyListAdapter extends ArrayAdapter<CommentInfo> {
public MyListAdapter()
{
super(Comment.this, R.layout.listview_xml, myComments);
}
#Override
public View getView(final int position, final View convertView, final ViewGroup parent)
{
itemView = convertView;
if(itemView == null)
{
itemView = getLayoutInflater().inflate(R.layout.listview_xml, parent, false);
}
CommentInfo currentComment = myComments.get(position);
TextView tvLikes = (TextView) itemView.findViewById(R.id.tvLikes);
tvLikes.setText(currentComment.likes);
ImageView ivLikes = (ImageView) itemView.findViewById(R.id.likeBtn);
ivLikes.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
likePosition = position;
TextView tvlikes1 = (TextView) convertView.findViewById(R.id.tvLikes);
// Here, i will get the correct value from DB and set it.
// I am setting 999 for sample purpose
tvlikes1.setText("999");
}
});
return itemView;
}
}
I reset the value of listview's text view by getting convertView value in getView() argument in my above adapter class and accessing my listview's textview widget through it. Then, i set it to value 999 (for example purpose). Now, I scroll down to get more new listView items. But, on scrolling up the new value (999) that i set to the old item disappears.
Please help me with it.
I have done a test myself. The ListView adapter will always take the values from the myComments list, so in order to update the TextView as you want, you have to do like this:
ivLikes.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
likePosition = position;
myComments.get(position).setLikes("999");//Assume that your CommentInfo's likes is a string.
notifyDataSetChanged();
}
});

Change the value of the Column in a grid in GWT

I am working on GXT 2.5.5
I have desinged a GRID in a project
In one column of the grid i have render a composite
It looks like this
This Choose evaluation column is Composite which is rendered in the Grid.
public class Evaluation extends Composite {
private RadioGroup rdgrpEvaluation;
private Radio radio_1;
// More radion buttons
private Radio radio_10;
}
All the radio_x.setValue(true) in the grid are set from the Model
int key = model.get("radioEvaluation");
switch (key) {
case 1:
evaluation.getRadio_1().setValue(true);
break;// more similar code
Now i want that when I click on radio button, the value of the Evalution column should also change.
Can some body help ?
I think that simplest way is call refresh whole table after selecting some button:
grid.getView().refresh(false);
But you also need to update your model.
When You click on radio button you may set value to your model like^
data.setEvalueation(int selectedRadio);
Or You can create specified ValueProvider to Evaluation column
ColumnConfig<Data,String> evaluationColumn = new ColumnConfig<Data, String>(new ValueProvider<Data>() {
#Override
public String getValue(Data o) {
String value = o.getRadioColumnValue();
return value;
}
#Override
public void setValue(Data o, Data o2) {
}
#Override
public String getPath() {
return "evaluation";
}
});

JavaFX8 TreeTableView notifications for scrolled items

I am writing an application that is using a JavaFX8 TreeTableView. The tree table has three columns, two of which are String properties (name and value) and one which has a Canvas widget in it that draws a picture from from data from a database (waveforms). There is also a control on the application that allows the display (of all of the drawings) to be zoomed out or in (or for that matter scrolled left and right).
The name and value columns use StringProperty values from my data model so there are CellValueFactory set for those columns. The drawing column uses both a CellFactory and CellValueFactory like this:
// Waveform column
TreeTableColumn<DrawRow, WaveformTraceBox> waveColumn = new TreeTableColumn<>();
waveColumn.setCellFactory(new Callback<TreeTableColumn<DrawRow, WaveformTraceBox>, TreeTableCell<DrawRow, WaveformTraceBox>>() {
#Override
public TreeTableCell<DrawRow, WaveformTraceBox> call(TreeTableColumn<DrawRow, WaveformTraceBox> param) {
return new WaveformTraceBoxTreeTableViewCell<>();
}
});
waveColumn.setCellValueFactory(new Callback<TreeTableColumn.CellDataFeatures<DrawRow, WaveformTraceBox>, ObservableValue<WaveformTraceBox>>() {
#Override
public ObservableValue<WaveformTraceBox> call(TreeTableColumn.CellDataFeatures<DrawRow, WaveformTraceBox> param) {
return new ReadOnlyObjectWrapper<>(new WaveformTraceBox());
}
});
Where WaveformTraceBoxTreeTableViewCell is:
protected static class WaveformTraceBoxTreeTableViewCell<T> extends TreeTableCell<DrawRow, T> {
public WaveformTraceBoxTreeTableViewCell() {
super();
}
#Override
protected void updateItem(T value, boolean empty) {
super.updateItem(value, empty);
setText(null);
setGraphic(null);
if (!empty && getTreeTableRow().getItem() != null) {
getTreeTableRow().getItem().setTraceBox((WaveformTraceBox)value);
setGraphic((WaveformTraceBox) value);
}
}
DrawRow is my data model. When the user zooms out or in via the controls on the window the draw row model will notify it's associated Canvas drawing item to re-draw its display. The drawing of the display can take some time to do because of the large amount of data that needs to be processed to generate the display.
Now my problem: As the TreeTableView widget is scrolled it will ask for new Canvas widgets -- which get associated with DrawRow items from the data model. However widgets from the list that get scrolled off the screen will get thrown away by the tree widget.
I have found no way to tell if the item I am working with has been thrown away or is not being used any more. So the code is doing much more work than it needs to because it is trying to draw cells that are no longer being used or shown. Eventually this will cause other problems because of garbage collection I think.
So my real question is how can I tell if a cell has been abandoned by the tree table so I can stop trying to update it? Any help with this would greatly be appreciated. I am not able to find this anywhere on the various web searches I have done.
Do you need to worry here? What is still "drawing cells that are no longer being used"? Are you running some kind of update in a background thread on the WaveformTraceBox?
In any event, you've structured this pretty strangely.
First, (less important) why is your WaveformTraceBoxTreeTableViewCell generic? Surely you want
protected static class WaveformTraceBoxTreeTableViewCell extends TreeTableCell<DrawRow, WaveformTraceBox>
and then you can replace T with WaveformTraceBox throughout and get rid of the casts, etc.
Second: if I understand this correctly, WaveformTraceBox is a custom Node subclass of some kind; i.e. it's a UI component. The cell value factory shouldn't really return a UI component - it should return the data to display. The cell factory should then use some UI component to display the data.
That way, you can create a single WaveFormTraceBox in the cell implementation, and update the data it displays in the updateItem(...) method.
So something like:
// Waveform column
TreeTableColumn<DrawRow, WaveformData> waveColumn = new TreeTableColumn<>();
waveColumn.setCellFactory(new Callback<TreeTableColumn<DrawRow, WaveformData>, TreeTableCell<DrawRow, WaveformData>>() {
#Override
public TreeTableCell<DrawRow, WaveformData> call(TreeTableColumn<DrawRow, WaveformData> param) {
return new WaveformTraceBoxTreeTableViewCell();
}
});
waveColumn.setCellValueFactory(new Callback<TreeTableColumn.CellDataFeatures<DrawRow, WaveformData>, ObservableValue<WaveformData>>() {
#Override
public ObservableValue<WaveformTraceBox> call(TreeTableColumn.CellDataFeatures<DrawRow, WaveformTraceBox> param) {
return new ReadOnlyObjectWrapper<>(getDataToDisplayForItem(param.getValue()));
}
});
protected static class WaveformTraceBoxTreeTableViewCell extends TreeTableCell<DrawRow, WaveFormData> {
private WaveformTraceBox traceBox = new WaveformTraceBox();
public WaveformTraceBoxTreeTableViewCell() {
super();
}
#Override
protected void updateItem(WaveFormData value, boolean empty) {
super.updateItem(value, empty);
setText(null);
setGraphic(null);
if (!empty && getTreeTableRow().getItem() != null) {
traceBox.setData(value);
setGraphic(traceBox);
} else {
setGraphic(null);
}
}
}
Obviously you need to define the WaveFormData class to encapsulate the data your WaveFormTraceBox will display, and give the WaveFormTraceBox a setData(WaveFormData) method. If you are using any resources that need to be cleaned up, the invocation of setData(...) will indicate that the previous data is no longer being accessed by that WaveformTraceBox.

Adding list sub-editors to tab panel

I use ListEditor to allow editing list of chilren and I do everything just like I saw in some examples.The only difference from examples is that I want widgets editing children to be added as a tabs to some TabLayoutPanel.
The problem is that I want to give a header to this new tab and this header is not constant but depends on object being edited by newly created sub-editor (so let the header be child.getName()) which I don't know inside EditorSource#create() method.
ListEditor<ChildProxy, ChildPanel> children = ListEditor
.of(new EditorSource<ChildPanel>() {
#Override
public ChildPanel create(int index) {
ChildPanel tab = new ChildPanel();
//here's a problem, how I can get tabHeader here?
tabPanel.add(tab,tabHeader);
}
});
How can I set value-dependent headers to tabs created by create()? Any help/workaround would be greatly appreciated.
Does this approach work for you :
public class ChildrenEditor extends Composite implements
IsEditor<ListEditor<Child, ChildInTabEditor>> {
ListEditor<Child, ChildInTabEditor> editor;
public ChildrenEditor() {
initWidget(uiBinder.createAndBindUi(this));
editor = ListEditor.of(new ChildInTabEditorSource());
}
private class ChildInTabEditorSource extends EditorSource<ChildInTabEditor> {
public ChildInTabEditor create(int index) {
ChildInTabEditor tab = new ChildInTabEditor();
// here's the trick :
Child child = editor.getList().get(index);
tabPanel.add(tab,child.getTabTitle());
return tab;
}
}
#Override
public ListEditor<Child, ChildInTabEditor> asEditor() {
return editor;
}
}
ChildInTabEditor must be a Tab that implements Editor<Child> then too!
What worked for me was passing tabPanel and index to newly created ChildPanel() and make it ValueAwareEditor. Then on setValue() I was setting header on tabPanel reference at given index.

popuppanel show up beneath the widget

I am new to GWT and the web stuff.
I am working out my own project based on
http://code.google.com/p/cloud-tasks-io/source/browse/#svn%2Ftrunk%2FCloudTasks-AppEngine%2Fsrc%2Fcom%2Fcloudtasks%2Fclient
I am trying to use popup/dialog. The popup and dialog always show behind the widget. I keep googling around and the most relevant I found is this
http://groups.google.com/group/gwt-google-apis/browse_thread/thread/40db4fcbe10d2060 which does not provide any answer. Anyway, I have 3rd party library, bst-player 1.3, which uses flash. So I disabled it(later remove it too), the popup just won't come to the top! It is still hiding behind the widget.
I have learned that popuppanel/dialogpanel alikes do not need to get added to another widget. A different way of saying is that it is not a normal widget in a sense that it cannot attach to a parent but it attaches itself to the dom to guarantee being on top (from GWT composite widget )
I am at my wit end and I am here at SO ...
UPDATE
Here is my Popup class
public class PopUp {
static PopupPanel simplePopup;
public static void init() {
simplePopup = new PopupPanel(true);
simplePopup.hide();
simplePopup.setVisible(false);
// DOM.setIntStyleAttribute(simplePopup.getElement(), "zIndex", 3);
}
public static void showpopupmsg(String msg, int left, int top) {
if (simplePopup == null) {
init();
}
if (msg != null && !msg.equalsIgnoreCase("")) {
simplePopup.ensureDebugId("cwBasicPopup-simplePopup");
simplePopup.setWidget(new HTML(msg));
simplePopup.setVisible(true);
simplePopup.setPopupPosition(left, top);
simplePopup.setWidth("475px"); //575
simplePopup.setGlassEnabled(true);
simplePopup.show();
}
}
public static void show(String message){
if (simplePopup == null) {
init();
}
simplePopup.setGlassEnabled(true);
simplePopup.setTitle(message);
simplePopup.center();
}
}
Here is how I am calling
tasksTable.doneColumn.setFieldUpdater(new FieldUpdater<TaskProxy, Boolean>() {
public void update(int index, TaskProxy task, Boolean value) {
String msg = "Here is the popup. All the way underneath";
Widget source = tasksTable;
int left = source.getAbsoluteLeft() - 50;
// source.getAbsoluteLeft() + 25;
int top = source.getAbsoluteTop() - 25;
PopUp.showpopupmsg(msg, left, top); //Here is the calling method
TaskRequest request = requestFactory.taskRequest();
TaskProxy updatedTask = request.edit(task);
updatedTask.setDone(value);
request.updateTask(updatedTask).fire();
}
});
Here is how the Popup is beneath the widget.
The source of the problem has been quite elusive since I am still new to the webapp, yet, I finally solve it myself. The culprit is the CSS. It is defining the z-index for the whole thing to quite high as seen in the following code line 1333.
http://code.google.com/p/cloud-tasks-io/source/browse/trunk/CloudTasks-AppEngine/war/CloudTasks.css#1333
I have doubted about the z-index before and try it out with a paltry value 3 as seen in the commented out code segment of Popup class in question. I have to uncomment it and set it to 101.
DOM.setIntStyleAttribute(simplePopup.getElement(), "zIndex", 101);
I was , you know, #$%###$*.
z-index is only decides which widget should show on top..
the widget popup is under benath might be having z-index value high.
set the z-index for popup thru css (recomended) or DOM will work for you
According to my feeling, using static methods of your "PopUp" object is a bit strange...
In that way, I think things a relative to the top rather than caller object.
Maybe you could consider make your class 'Popup' extending 'popupanel'
and in your calling code, just make
new PopUp(msg,left,top).show() ;
I recently wrote my own solution for a popup panel that needs to be aligned with its caller. The solution consists out of an PopupPanel extension and a Button extension.
The button extension has an instance of the panel extension, and the moment it is clicked it gives its coordinates and width and height to its panel.
#Override
public void onClick(ClickEvent event) {
if (optionsPanel.isShowing()) {
optionsPanel.hide();
} else {
optionsPanel.setButtonBounds(new Bbox(
getAbsoluteLeft(), getAbsoluteTop(), getOffsetWidth(), getOffsetHeight()));
optionsPanel.show();
}
}
(The Bbox class is just a convenience class I could use for wrapping coordinates; write your own class or 4 methods for that matter)
The main work is then done in the onLoad() override of the PopupPanel, in which the coordinates of the button are used to position the panel;
#Override
protected void onLoad() {
super.onLoad();
if (null == bounds) {
super.hide();
} else {
left = (int) bounds.getX();
top = (int) bounds.getMaxY();
setPopupPosition(left, top);
}
}
(bounds are the coordinates of the button; getMaxY() == bottom coordinate of button)