I have a View class (extends ViewPart) that contains a ScrolledForm created from a FormToolkit. When certain events happen in other views in the app I want to change the form in this view and have it update in real time to the user.
I have property change support support added now and the following method in the View
public void propertyChange(PropertyChangeEvent event) {
form.dispose();
toolkit.dispose();
createForm( event );
form.redraw();
}
where createForm( event ) recreates the form based on the event.
The problem is that the UI does not display the new form after this. I know the form is created OK because if I drag the border between the View and another view to resize it then the View is immediately updated to show the new form. How can I programmatically force the refresh of the view in the UI?
Have you tried: form.reflow(true); ?
This will recompute the layout of the form.
If this fails than try calling xxx.layout(true) where 'xxx' is the variable mame of the SWT Composite that is the parent of the form instance. I assume the form is created against its parent composite in your createForm( event ) method?
Related
In my activity I try to call a method from a class but it's not getting the right values.
This is ActivityTwo:
int id = intent.getIntExtra("id", 0);
LayoutInflater inflater = getLayoutInflater();
View mainActivity = inflater.inflate(R.layout.activity_main, null);
LinearLayout eventsLayout = mainActivity.findViewById(R.id.eventsLayout);
Log.d("ACTIVITY_eventlayout", String.valueOf(eventsLayout)); // gives the layout perfectly
Event.RemoveSpecific(eventsLayout, id);
finish();
This is the class(Event) with the method:
public static void RemoveSpecific(LinearLayout layout, int id){
View event = layout.findViewById(id);
Log.d("INSIDE_removespecific", String.valueOf(event));// event is null
layout.removeView(event);
}
And in my MainActivity it's working fine:
LinearLayout eventsLayout = findViewById(R.id.eventsLayout);
View event = eventsLayout.findViewById(id);
//Log.d("MAIN_event", String.valueOf(event1)); // gives it perfectly
eventsLayout.removeView(event);
I also add this view in my MainActivity and use .setId(id) to give it the right id. So my question is, why is the View in my class method null, while I pass the right LinearLayout from my activityTwo?
Where does the id come from?
I have the Event class which contains an id, name, date, & description. This class also has a static ArrayList called eventsList. Whenever the user creates a new reminder I create a new Event using my class and giving it an id as Event.eventsList().size() (after adding it to my eventsList [so the first event id is always 1]), then I create a new View and pass the recently created Event details and use setId() to give it an id [1]. Then in this View I have a button which has an onClickListener which passes the given View id and the LinearLayout (where the View was added) to my Event.removeSpecific() method.
App flow:
The user clicks a button in MainActivity to create an event, then the button click then use startActivityForResult() with an intent to open a new Activity where the user puts in a name,description and date for the event, then I create an intent with putExtra() methods and then use setResult(RESULT_OK, resultintent) to send the data back to MainActivity. Now when the MainActivity gets the data back I use .getStringExtra() to create a new Event object with the data and add it to may Event.eventsList ArrayList, then I use the following:
LayoutInflater inflater = getLayoutInflater();
View event_Exmaple = inflater.inflate(R.layout.event_example, null);
and set the textView's with the data I got, and use event_example.setId(Event.eventsList.size()) to give it an id.
After that I add this to my LinearLayout (which I declared already in the MainActivity):
eventsLayout.addView(event_example)
Now I mentioned that the Event class has a date field. I use that to set up an alarm with AlarmManager. With the AlarmManager I send the current Event object's data through the intent and when the user gets the notification it opens up a new Activity which gets the given Event object data (with intent.putExtra()'s) and that's the part where the user clicks on a Button. I want to remove the given Event object's View from my LinearLayout in the MainActivity XML.
well since you didn't share where the id value come from (from where the intent gets its data/how you put the values in it/where the values come from), I assumed this solution :
whenever I use a 'switch' statement with View Ids it tells me a very important warning which is
Resource IDs will be non-final in Android Gradle Plugin version 5.0, avoid using them in switch case statements
that means that view Ids doesn't have a stable id in some cases that you shouldn't consider them to be final.
I guess in your case when you get an id to your event view and then inflate the layout view, the inflate procedure involve changing the 'int' id value of the event view so whenever you query the old id it returns null since the event view inside the inflated layout view now has a new 'int' id value.
I don't know why it works in main activity since you didn't share full code where you get the id from.
so I guess the only solution is that you should find a way to get a fresh copy of the id after you inflate the view you want to work on in the method.
Update
the problem is with this block of code
View mainActivity = inflater.inflate(R.layout.activity_main, null);
everytime you inflate a new layout view thinking that you have the one used by main activity back there but instead you're creating an entirely new one with new views and new Id's.
that would be why you could get the view in main activity but you can't get it from a newly inflated view.
Update
if you need to remove this item using the id and have a static array stored in the view custom class, call a getter on the static array and remove the item from it instead of trying to remove the view itself.
a better implementation of the whole situation is to store these events in a database using room instead of the static array, that way you could delete/add/edit any event anytime with just one line of code, if you're willing to do this you can start by reading the developers documentation of room.
I have an Eclipse RCP with a view whose Control is a CheckboxTableViewer.
I'd like to use the WorkbenchPage's SelectionService (for reasons of loose coupling) to react to check/uncheck actions within the view in an editor.
So I do getSite().setSelectionProvider(myTableViewer); in the view's createPartControl() method.
Also, I create a listener field in the editor:
private ISelectionListener mylistener = new ISelectionListener() {
public void selectionChanged(IWorkbenchPart sourcepart, ISelection selection) {
System.out.println(((IStructuredSelection) selection).size());
}
};
Unfortunately, I only get the number of rows that are selected printed out in the console, not the number of checked elements. I'm trying to pass myTableViewer.getCheckedElements() to the SelectionProvider somehow, but cannot find an access point :(.
You could write your own implementation of ISelectionProvider which returns the checked elements instead of using the default provider implemented by TableViewer which returns the selected elements.
I created a function inside my plugin project (a plugin which contains a view), that creates selection listeners for an active page (for example: package explorer, resource navigator).
At the first execution of an Eclipse instance sometimes I don't have an active page and the following is null:
ISelectionService selectionService=PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
So that a selection listener cannot be setted for another view:
selectionService.addSelectionListener(partID,listener);
My problem is actually that the function doesn't executes the above line since the selectionService is null.
What should I do in order to avoid this situation ?
One way is to add a IWindowListener to the IWorkbench and then add the selection listener in the windowOpened event:
IWorkbench workbench = PlatformUI.getWorkbench();
workbench.addWindowListener(window listener);
...
#Override
public void windowOpened(IWorkbenchWindow window)
{
window.getSelectionService().addSelectionListener(selection listener);
}
I'm using a viewpager which is made up of some number of relative layout siblings which are quite complex.
If I click on the relative layout, it will highlight the entire page and read the title and a few textviews one after the other as expected.
If I scroll the viewpager I'd like talkback to read the next page in the same way it reads the first if I click. Secondly, if I scroll to the second, third, etc. pages and click on those layouts, talkback will read as expected.
I am trying to achieve the click behavior after the scroll event has completed.
Here is what I have for the accessibilityDelegate.
viewPager.setAccessibilityDelegate(new AccessibilityDelegate () {
#Override
public boolean onRequestSendAccessibilityEvent(ViewGroup host, View child, AccessibilityEvent event) {
if (event.getEventType() == AccessibilityEvent.TYPE_VIEW_SCROLLED) {
View page = viewPager.getCurrentPageView();
performAccessibilityAction(page, AccessibilityNodeInfo.ACTION_CLICK, Bundle.EMPTY);
}
return super.onRequestSendAccessibilityEvent(host, child, event);
}
});
I've verified that 'page' is the RelativeLayout parent that I think it is. I've also confirmed that the onRequestSendAccessibilityEvent is being fired, but it doesn't read the contents of its children. Am I missing something?
Updated
I've also tried using
viewpager.getCurrentPageView().sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_FOCUSED);
The above worked for another example when I needed to force talkback to reread a single item but does not have any affect if I try it on the page.
Thanks
Some background -- When you tap on the relative layout, TalkBack generates speech based on the layout's contents. On ICS, this is triggered by a HOVER_ENTER event. On Jelly Bean, it's triggered by an ACCESSIBILITY_FOCUS event. These events are sent automatically by the framework and should, generally speaking, never be sent manually from an app. The same goes for FOCUS events, except in the special case of custom views (see Accessibility talk from Google I/O 2013 for more details).
So, back on topic.
You can control the speech for SCROLLED events by populating the outgoing event with the text you want read. The down side of this is that you'll need to manually generate the text you want read, and it's very likely that this text will differ from what TalkBack will read if the user touches the layout.
viewPager.setAccessibilityDelegate(new AccessibilityDelegate () {
#Override
public void onPopulateAccessibilityEvent(View host, AccessibilityEvent event) {
super.onPopulateAccessibilityEvent(host, event);
if (event.getEventType() == AccessibilityEvent.TYPE_VIEW_SCROLLED) {
event.setContentDescription(/** your text */);
}
}
});
Another option is to do nothing and let the user explore the view on their own. This is the preferred interaction model for Android accessibility.
Edit: Video URL is broken, Changed.
This issue was reported on google check
where ViewPager does not set AccessibilityEvent parameters properly
when scrolling.
But after releas of Android Support Library, revision 23.2.1 (March 2016) This issue has been resolved.
update Support Library to Android Support Library to 23.2.1
I had the same issue before. And now I add android:focusable="true" to the ViewGroup, the TalkBalk will read the ViewGroup, instead of its children
I am retrieving a List<String> strings from my database and i would like to display it in a Flex Table.Also with every row in the flex table i want a delete button.The delete button on click should remove the row from the flex table.
so i write code some thing similar to
for(int i =0 ;i < strings.size();i++) {
flexTable.setWidget(i,0,strings.get(i));
flexTable.setWidget(i,1,new Button("X");
}
Now i am using MVP architecture to write this code.The reason why i am specifying this is i want all the widgets declared in my View and the click handlers to be in my presenter.
Generally if i have Button b = new Button("Sample Button"); in my View
I can have a getter method and use getButton.addClickHandler(new ClickHandler())
in my presenter.
But here i am creating delete buttons on fly.
So how can i assign a click handler to the delete Button and onClick i should be able to remove the row from the flextTable.
Thanks
Just register the handlers in the View and provide a Callback type class from the Presenter that receives each String that is deleted.