How to slide a listview by interacting with seekbar - android-listview

I have a listview and a seekbar, i want the listview to react accroding to the interaction with the seekbar.
For ex :- if the seekbar is dragged to either ends, the listview should automatically go up or down.
Any help is greatly appreciated.

You should be able to use the list view method:
smoothScrollToPosition(int)
and OnSeekBarChangeListener
Set an OnSeekBarChangeListener on your seekbar.
In onProgressChanged add code using smoothScrollToPosition to update the listvew position.
Something like this:
public void onProgressChanged (SeekBar seekBar, int progress, boolean fromUser) {
listView.smoothScrollToPosition(progress); //assuming you have a 1 seekbar position for each row in the list, otherwise you'll need to do some calculation to compute the new list view position.
}
alternatively, you could use the onStopTrackingTouch method if you only want to scroll to the final position the user touched in the seekbar.

Related

Range Slider with ETO form

A range slider is a slider with two "knobs" and the second "knob" must always have a value > that of the first "knob".
What would be the best way to achieve a range slider in ETO forms?
looks like the Slider : Control class does not expose enough information to create a slider with double Knobs.
Perhaps one way to "fake" it is to put two slider objects side by side, where the value of the first slider becomes the min value of the second slider (this will require some resizing too)?
If we were to create a custom double slider object,
http://pages.picoe.ca/docs/api/html/T_Eto_Forms_Slider.htm
To create custom controls in Eto.Forms, you can use the Drawable class, which gives you a Paint event that you can draw the UI you need, handle mouse events, etc. Setting CanFocus to true allows it to be focused so you can handle key events. For example:
public class RangeSlider : Drawable
{
public RangeSlider()
{
CanFocus = true;
Size = new Size(200, 20);
}
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
// draw the range slider using e.Graphics
}
}

Unity, scalling the width of a dynamically created Gameobject in a a scroll view content box

I am trying to add 100 dynamically created buttons to a scroll view in Unity, but I have a problem letting the scroll view automatically adjust the width of the buttons to match the width of my screen.
When I tried to add the buttons manually it worked fine , but when I do this by code I get another results.
The code I am using :
public GameObject button;
public GameObject scrollviewcontents;
void Start()
{
for (int i =0; i<=100;i++) {
GameObject dbutton = Instantiate(button);
dbutton.name = i.ToString();
dbutton.transform.parent = scrollviewcontents.transform;
}
}
and The results I get :
Results
Results with comments
I just want the buttons to look like as they are added manually, any help ???
By default when instantiating an object the object keeps the same world space position, rotation and scale as before. try this instead:
dbutton.transform.SetParent(scrollviewcontents.transform, false);

javafx: How can I put slider tick labels above its sliding track in horizontal slider?

I am trying to customize the horizontal slider such that its major tick labels appear above sliding track (by default they appear below sliding track) and major tick label values appear in reverse order. Do I need to use CSS somehow to display the labels above sliding track?
So far I have reversed the labels ordering using setLabelFormatter:
final double sliderMax = slider.getMax();
slider.setLabelFormatter(new StringConverter<Double>() {
#Override
public String toString(Double d) {
return String.valueOf((int)(sliderMax - d));
}
#Override
public Double fromString(String str) {
return (sliderMax - Double.parseDouble(str));
}
});
Any pointers will be helpful.
This is certainly possible with CSS.
This will only work for horizontal Slider though. Theoretically there is the pseude CSS class horizontal on the Slider which could be used to restict the CSS to horizontal Sliders, but I was unable to test this, maybe you can make it work.
Check out the CSS-Refrence and inspect your application with ScenicView.

How to Drag and Drop Custom Widgets?

I have created my own custom widget and I want to support internal drag and drop for the widgets.
I have added 4 of my custom widgets in a vertical box layout. Now i want to drag and drop the custom widgets internally. To be more clear, If i drag the last widget and drop it in the first position, then the first widget has to move to the second positon and the last widget (which is dragged) has to move to first position. (same like drag and drop of the items in the List view). Can anyone suggest me a way to drag and drop of the custom widgets.
You need to reimplement mousePressEvent, mouseMoveEvent and mouseReleaseEvent methods of a widget you want to drag or install an event filter on them.
Store the cursor position in mousePressEvent and move the widget in mousePressEvent to the distance the cursor moved from the press point. Don't forget to clear the cursor position in the mouseReleaseEvent. The exact code depends of how you want the widget to look when is being dragged and how other widgets should behave when drag/drop the widget. In the simplest case it will look like this:
void mousePressEvent(QMouseEvent* event)
{
m_nMouseClick_X_Coordinate = event->globalX();
m_nMouseClick_Y_Coordinate = event->globalY();
};
void mouseMoveEvent(QMouseEvent* event)
{
if (m_nMouseClick_X_Coordinate < 0)
return;
const int distanceX = event->globalX() - m_nMouseClick_X_Coordinate;
const int distanceY = event->globalY() - m_nMouseClick_Y_Coordinate;
move(x() + distanceX, y() + distanceY());
};
void mouseReleaseEvent(QMouseEvent* event)
{
m_nMouseClick_X_Coordinate = -1;
}

I need to know when a VerticalPanel changes size

I'm using gwt-dnd to implement drag-and-drop functionality in my GWT program. To get scrolling to work right, I need
<ScrollPanel>
<AbsolutePanel>
<VerticalPanel>
<!-- lots of draggable widgets -->
</VerticalPanel>
</AbsolutePanel>
</ScrollPanel>
I have to manually set the size of the AbsolutePanel to be large enough to contain the VerticalPanel. When I add widgets to the VerticalPanel, though, the size reported by VerticalPanel.getOffsetHeight() isn't immediately updated - I guess it has to be rendered by the browser first. So I can't immediately update the AbsolutePanel's size, and it ends up being too small. Argh!
My stop-gap solution is to set up a timer to resize the panel 500ms later. By then, getOffsetHeight will usually be returning the updated values. Is there any way to immediately preview the size change, or anything? Or, alternatively, can I force a render loop immediately so that I can get the new size without setting up a timer that's bound to be error-prone?
This is a common problem with DOM manipulations. The offsetHeight doesn't update until a short time after components are added. I like to handle this using a recursive timer until a pre-condition is violated. E.g. In your case let there be a function which adds components and will be defined as below:
public void addComponent(Widget w)
{
final int verticalPanelHeight = verticalPanel.getOffsetHeight();
verticalPanel.add(w);
final Timer t = new Timer(){
public void run()
{
if(verticalPanelHeight != verticalPanel.getOffsetHeight())
absolutePanel.setHeight(verticalPanel.getOffsetHeight() + 10 + "px");
else
this.schedule(100);
}
};
t.schedule(100);
}