scrollView.fullScroll(View.FOCUS_DOWN); always is triggered - java

OK,i have ScrollView with multiply recyclerview-s.When user click on some item on my list that item expand itself with some more info. The problem is that although it does expand correctly, my root view(in my case ScrollView) does not follow that expansion automatically ,so i need to scroll manually to see expanded item.So i used scrollView.fullScroll(View.FOCUS_DOWN) in onClick in my recyclerview.And it works fine but after this line of code is triggered every other click on some other recycelerView it scroll down although that recyclerview does not have fullScroll().
I tried to use scrollTo(),smoothScrollTo etc.I dont use ExpandableRecyclerView but cachapa/ExpandableLayout and in this thread developer said that it is rather the parent View "issue".Also tried solution from the same thread but problem persist.
So my question is how to stop triggering fullScroll(View.FOCUS_DOWN) when i click on other recuclerviews items.
my code:
` animaton.setOnClickListener(v -> {
notifyDataSetChanged();
//some stuff
scrollView.post(new Runnable() {
public void run() {
scrollView.fullScroll(View.FOCUS_DOWN);
}
});
});`

Related

Vaadin unbuffered grids won't close

I am having a weird problem on my Vaadin app. I have a screen with two separate unbuffered grids.
The user is able to edit the data in those two grids and then click a "Save" button to save the changes made.
My problem is that I want to close the editors when the user clicks on "Save".
I tried the following code:
private void closeEditors() {
if (tab1.getEditor().isOpen()) {
tab1.getEditor().closeEditor();
}
if (tab2.getEditor().isOpen()) {
tab2.getEditor().closeEditor();
}
}
I don't understand why this code doesn't work, editors stay opened. I also tried calling the cancel method but in vain.
I am using Vaadin 14.
I am posting this here with not much hope of finding an answer, this problem seems really precise.
But with any luck, maybe someone has experienced a similar issue ?
Maybe there is another glitchier way of forcing my editors to close ?
Any suggestion would be of great help, thanks in advance for anything you could think of !
EDIT: a little more code
This is the grids:
private Grid<Map<String, String>> tab1;
private Grid<Map<String, List<String>>> tab2;
This is the save function
public void saveData() {
saveDataFromTab1();
saveDataFromTab2();
try {
ServicesProxyImpl.getInstance().updateInBD(someObject);
saveButton.setEnabled(false);
cancelButton.setEnabled(false);
closeEditors();
Dialog dialog = VaadinComponentUtils.generateDialog(Constantes.MSG_SAVE_OK);
dialog.open();
} catch (JAXBException e) {
e.printStackTrace();
Dialog dialog = VaadinComponentUtils.generateDialog(Constantes.MSG_SAVE_KO);
dialog.open();
}
}
And this is the save button:
public Button getSaveButton() {
Button saveButton= VaadinComponentUtils.generateButton("Save",
VaadinIcon.CHECK_CIRCLE_O, null, true);
saveButton.setEnabled(false);
saveButton.addClickListener(event -> saveData());
return saveButton;
}
EDIT 2:
I have noticed something, when I click on an element of one of my two grids, I want the editor to open for that specific element and I want to close the editor on the other grid (the one not concerned by the modification). This works ! My grids behave like I want. It seems I am only losing control over my editors after I have actually modified one of the cells and clicked on my save button.
The isOpen function returns false on both grids after I call my closeEditors function, so it seems the grid thinks its editor is closed but it is still opened on my UI.
EDIT 3: I have found a workaround
Well, I have solved my problem by adding a close event listener on both my grids and calling resetGrids when the close event is fired. This function simply removes the grids from the UI, fetches the data to be displayed and then adds the grid one again, both editors being closed. I guess it solves my problem but I would have wanted to understand what was going on...
private void closeEditors() {
tableauHoraires.getEditor().addCloseListener(e -> resetGrids());
tableauRamassagePorteAPorte.getEditor().addCloseListener(e -> resetGrids());
if (tableauRamassagePorteAPorte.getEditor().isOpen()) {
tableauRamassagePorteAPorte.getEditor().closeEditor();
}
if (tableauHoraires.getEditor().isOpen()) {
tableauHoraires.getEditor().closeEditor();
tableauHoraires.getEditor().refresh();
}
}
Make sure that the objects in your grid have proper equals and hashcode methods and that the field(s) being edited do not influence them.
I use the PK from the database.

How to communicate between a RCP workbench toolbar and RCP views

I have a RCP application with some views and an ActionBarAdvisor that creates a toolbar for the application. The toolbar is initialized like this:
public class ApplicationActionBarAdvisor extends ActionBarAdvisor
...
protected void fillCoolBar(ICoolBarManager coolBar)
{
// Create new Toolbar
IToolBarManager toolbar = new ToolBarManager(coolBar.getStyle());
// Adds toolbar to perspective
coolBar.add(toolbar);
...
ActionContributionItem compareFilesCI = new ActionContributionItem(compareFiles);
compareFilesCI.setMode(ActionContributionItem.MODE_FORCE_TEXT);
toolbar.add(compareFilesCI);
...
}
The purpose of this toolbar item is to switch the color of the values of a JFace table. The user can switch the coloring in the table on or off by pressing the button.
But what is the best way to tell the table that coloring should be enabled/disabled? At the moment I've done it this way:
public class ActionCompareFiles extends Action implements ISelectionListener, ActionFactory.IWorkbenchAction
{
...
public void run()
{
// Check if the button is enabled. When it is enabled, comparison should be performed
try
{
// Get the label values view
final ViewFileValues labelViewer = (ViewFileValues) PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getViewReferences()[3].getView(true);
// Refresh the view
labelViewer.setColoringValues(this.isChecked());
}
catch (Exception e)
{
System.out.println("Exception when searching the values view");
}
}
...
When pressing the button, I get the view that contains the table. Within this view class is a method 'SetColoringValues' that informs the label providers for the table columns that the button was pressed and updates the table.
This works but I'm not sure if it is the best solution...
My first idea was to simple add listeners to the button. After pressing the button, the listeners will be informed. But this seems not to work because I don't get the ActionBarAdvisor object, were the
toolbar was created. There seems to be no getter method for the toolbar that is part of the workbench window.
What is the best solution for this problem?
1) you should better use the Eclipse RCP commands framework (extension points *.commands, *.handlers, *.menu) instead of implementing this the way you do. It may look cumbersome at the first glance but in fact it is much more structured and straightforward.
2) the way you get an instance of the view is totally wrong: you rely upon the fact that the view has index of 3 in the page which is never warranted.

Hiding ActionBar on touching surface

I'm writing a very simple android app. When the user touches the surface and moves their finger around, pictures are drawn below their fingers. When their finger is raised, this stops.
I want the action bar to hide when the finger is down and reappear when it is raised.
The ActionBar is overlayed. I thought using ActionBar.hide() and .show() in my view's onTouchEvent would work fine, but I've hit some problems.
I've tried a few things. First I tried passing the ActionBar created in the Activity into the view, but this didn't work as the view has to be created before the ActionBar is "got", so I would just be passing in a null value.
I then tried to make a static ActionBar which I can call from my view, but then I get this error: "Only the original thread that created a view hierarchy can touch its views.”
Anyone know of a way around this?
Take a look at one of the examples that is part of the jfeinstein10's Sliding Menu library
In it, in the BirdActivity.java, you will see how the ActionBar is shown and hidden after 2 seconds. You will naturally have to adapt the code yourself. But this should get you started:
Excerpt of the code from Line No. 53 - 58:
imageView.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
getSupportActionBar().show();
hideActionBarDelayed(mHandler);
}
});
The hideActionBarDelayed() from Line No. 80 - 86:
private void hideActionBarDelayed(Handler handler) {
handler.postDelayed(new Runnable() {
public void run() {
getSupportActionBar().hide();
}
}, 2000);
}
UPDATE
For the lack of code, most of the problem has been assumed. It may be wrong simply for the lack of data from the OP. That being said, if sorting out the "Only the original thread that created a view hierarchy can touch its views." problem will fix it, perhaps this may do it for you:
Runnable run = new Runnable() {
#Override
public void run() {
// RUN YOUR CODE TO HIDE / SHOW THE ACTIONBAR HERE
}
}; YOUR_ACTIVITY.this.runOnUiThread(run); // REPLACE WITH getActivity().runOnUiThread(run); IF THIS IS A FRAGMENT
NOTE: In the example, the activity in question uses ActionBarSherlock and extends SherlockActivity and therefore, the use of getSupportActionBar(). If you are not using ABS, you will have to use getActionBar() instead of the former.

Change stage titleProperty on selecting different tabs in javafx

I guess there should be some event for this, but didn't find any. The code I have now is
stage.titleProperty().bind(tabPane.getSelectionModel().getSelectedItem().textProperty());
But it doesn't change the title dynamically, what's the right solution?
Puce's explanation is correct. Here is a change listener example.
stage.setTitle(tabPane.getSelectionModel().getSelectedItem().getText());
tabPane.getSelectionModel().selectedItemProperty().addListener(new ChangeListener<Tab>() {
#Override public void changed(ObservableValue<? extends Tab> tab, Tab oldTab, Tab newTab) {
stage.setTitle(newTab.getText());
}
});
Use the above code instead of the sample code in your question.
I can't give you a solution right now, but I think I spot the problem:
You've bound the titleProperty to the textProperty of the tab which was selected at binding time. You probably need to listen for selection changes and change the stage title in the listener.

Tab longClick problem in android

I have 5 tabs and I want to call a function on it's longclick (onLongClick()).
The longclick is working but when I release the touch the click (onClick()) function is also called along with it.
Please anyone help me on this problem.
It happens. I also had the same problem while implementing OnItemClickListener and OnItemLongClickListener.
You can accomplish this with a vairable value:
int i=0;//declare this as outside all methods
void onClick(...)
{
if(i==0)
{//your code
}
else
{
i=0;
}
}
void OonLongClick(...)
{
//your code
i=1;
}
this won't stop onClick from being called on long click but will fulfill your purpose by not performing the task you want to perform only on onClick().
Another method is to call another activity using intent from method onLongClick(). This will stop onClick() from being called because the control will move to another activity.

Categories