After a lot of searching, I can not find a solution to my problem.
The summary of my program I ve also checked with a tabhost.
It's viewpager viewpager has fragmentpageradapter who get an instance vector fragments, the fragments will identified by their position in the vector.
The first fragment instantiates a listefragment using a simpleadapter.
The listfragment is loaded with json data oncreate.
In the GetView method of simpleadapter, I change a textview in one of the item using a button on the item and a textview which'm part of an instance of this fragmentactivity.
I have listfragment with different json given 4 different positions in my viewpager.
When I press the button on my item, my textview and change correct.
My problem
When I turn pages in my viewpager and I return to the previous page of my viewpager, all calls to this issue 0
My question
how to save and restore the state of the items in my listfragment?
Or do I make these?
My Attempts
Save and restore the fragment in my listfragment use a static method in the viewholder GetView of simpleadapter I'm turning around ............
Thanks
in advance for your help
After a week of research and have posted a question on this great forum.
I finally found my problem question.
Here is the solution
this.mViewPager = (ViewPager) super.findViewById(R.id.tabviewpager2);
this.mViewPager.setOffscreenPageLimit(this.mPagerAdapter.getCount());
Link stackoverflow
Saving Fragment state in ViewPager
link android
http://developer.android.com/reference/android/support/v4/view/ViewPager.html#setOffscreenPageLimit%28int%29
Related
I am creating a chat view and loading images in a chat room using NetworkImageView (placed inside a Normal ListView) via Android Volley Framework, which works great but the problem is that when the chat gets loaded the images are downloaded after a while due to which scrolling to the bottom does not work as expected. What I want is the listview in which the images are kept should scroll to the end upon getting initialized.
Here is the code that does the scrolling to the bottom of the list:
listview.clearFocus();
listview.post(new Runnable() {
#Override
public void run() {
listview.setSelection(listview.getCount() - 1);
}
});
However, this does not scroll to the end of list. The issue is that volley does not load up the image by the time it is initialized and only initializes it when it is starting to get displayed (onAttachToWindow or onLayout calls). Refer to the code
A workaround to make sure the list gets scrolled is:
networkImageView.setImageResource(R.drawable.placeholderImage);
Although not a good solution, this gets the job done.
Anyone has better ideas?
Using setStackFromBottom(true) solves the issue. I don't know why it never came to my mind. Anyways, putting the question for people like me, having issues with volley.
I have problem a with getting VLayout height after I add a member to it
VLayot layout = new VLayout();
in presenter I have code
display.getAnswerPanel().removeMembers(display.getAnswerPanel().getMembers());
which clear all members, and I add another (I have buttons, when I clik them, it clears all VLayout and adds new members)
layout.addMember(new Button("Example"));
I need to get offsetHeight of this VLayout on start and everytime I click the button, my problem is that in first time when I load the page, my `offsetHeigh is 1px, each next time when I click button is ok, it shows me the correct value. Can someone help me?
I tried to use this code
scheduler.get().scheduleDeferred(new Scheduler.ScheduledCommand() {
layout.getOffsetHeight();
}
but the situation is the same, First time I don't have the correct value.
we can get the height and width of any widget only after the widget is being loaded or on button click.
Scheduler#scheduleDeferred() executes at the end of the GWT loop, so there's still no time for the layout to update either. I guess there's not much you can do besides using the traditional timer hack (in case any reader is in doubt, yes, I meant using setTimeout() or Scheduler.get().scheduleWithFixedDelay(cmd, 200) ).
I tried to use DataGrid and put it in the stacklayoutpanel.At the time when I provide the data for the ListDataProvider, the CellTable is not visible in the browser because it's on a non active tab (although it's visible in the DOM tree). After switching to the tab containing the CellTable there is no data in it. If the tab is active at time of data provisioning the table is filled correctly. Since I have made a column sortable, if I clicked the sorting, the data would be displayed correctly. I want the data to be displayed automatically when I click the other inative tab. This will not be the problem if I switch to use celltable.
I knew this was the bug in GWT and it is fixed in GWT 2.5 RC. But my boss does not want me to use GWT2.5RC yet. I have to workaround to fix this. I knew that someone said datagrid.redraw() could sort of fix it. I tired it, but the display is weird. For example, I have 10 rows in DataGrid, after selecting the 2nd tab, redraw() is called, the data is automatically displayed, but there is only like 10px of block displaying the data and the scroll bar. I have to scroll down to see other rows. There are lots of space in the bottom of the tab not being used. Could anyone tell me how to fix this? So did I use the wrong way to fix it?
is there anything else I can do to fix this problem.
Could anyone give me some tips please.
Thanks
Best Regards
I have been struggled with this thing for almost 3 days. Thanks for Papick G. Taboada and Thomas Broyer.
You guys' ideas are really helpful. Bascially either of your solution does not solve the problem. but after I combined both solutions, dang~ it worked!!.
So. the completed solution is that, add the selection handler on the non-active tab, then when the event is called, used datagrid.onResize() and then stackLayoutPanel.forcelayout(). This can solve my problem. I have also tried replacing datagrid.onResize() with datagrid.redraw(). It works as well.
I hope this can help other people who have the same problem before using GWT 2.5RC
I came across this problem with a DataGrid within and Panel that was in a StackPanelLayout. DataGrid implements RequiresResize, so I made the Panel that contained the DataGrid implement RequiresResize so it could call onResize() for the DataGrid.
in the Panel that contained the DataGrid
#Override
public void onResize()
{
dataGrid.onResize();
}
On the StackLayoutPanel
stackLayoutPanel.addSelectionHandler(new SelectionHandler<Integer>() {
// http://code.google.com/p/google-web-toolkit/issues/detail?id=6889
#Override
public void onSelection(SelectionEvent<Integer> event) {
Integer selectedItem = event.getSelectedItem();
StackLayoutPanel panel = (StackLayoutPanel) event.getSource();
Widget selectedWidget = panel.getWidget(selectedItem);
if (selectedWidget != null && selectedWidget instanceof RequiresResize)
{
((RequiresResize)selectedWidget).onResize();
}
}
});
I believe a more general answer would be that any container in a StackLayoutPanel that contains a widget that implements RequiresResize should also implement RequiresResize and pass it on.
I am trying to create a small Android App. The app will have four modes. The top part of the display will contain four buttons to switch between these modes, and this part of the display will not change. The rest of the display will change depending which button has been clicked on. It will contain a table with TextViews or images.
My questions are:
Is it possible to create the table layout programmatically?
How should I approach switching between modes:-
Four separate Activity classes?
One Activity and programmatically change the bottom part of it?
Should I create one base Activity with buttons and extend it?
What would be the best option?
Create layout by code is not the good solution. If your table layout is simple, I think it's not a big problem.
Here is a simple code how to create a layout by code :
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
LinearLayout layout = new LinearLayout(this);
layout.addView(new TextView(this));
setContentView(layout);
}
And as you see, it looks ugly !
Hope this help :)
#: Edit for additional question about Relative Layout:
In RelativeLayout (and some Layout of android), there is an object LayoutParamsto determine some properties of sub-layout (TextView, Button... is called sub-layout too if you put in other Layout)
Here is an example :
RelativeLayout layout = new RelativeLayout(this);
TextView textView = new TextView(this);
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(
RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.FILL_PARENT);
params.addRule(RelativeLayout.BELOW, textView.getId());
layout.addView(textView, params);
You should notice BELOW, it is one of many int constant such as Right_of.... You can see on Android Document about these.
I don't know RCP very well yet, but I've been reading a lot of the docs. I don't know if my question makes sense; I apologize if not and beg that you try to work out what I mean and come up with some kind of answer.
I have a tree view element, which has a double click listener on it. In another part of the window there is a layout folder which contains views that are supposed to be inspectors for the items double-clicked on.
The only way I know to make another inspector appear is:
getActivePage().showView(Inspector.ID).
showView() doesn't give any opportunity to pass extra information to the view, so can it know which element to inspect?
Pointers in different directions appreciated. The Vogel tutorial doesn't seem to cover this, or I don't understand it.
You could check if the article "Link to Editor" can help you here.
That is, instead of trying to access the right view, define a Listener for the Editors:
private IPartListener2 partListener2 = new IPartListener2() {
public void partActivated(IWorkbenchPartReference ref) {
if (ref.getPart(true) instanceof IEditorPart)
editorActivated(getViewSite().getPage().getActiveEditor());
}
That way, you can get back the right Editor, and ask that Editor all you need for your View to update accordingly.
You can use the SelectionService. The Inspector view should register as a SelectionListener. And the other view with the tree should register a SelectionProvider. This view should listen for the double click in the tree and then update the selection