In the Main Layout I have a ViewFlipper with two ListView inside, follows an excerpt.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/chinese_background"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context=".MainActivity" >
[...]
<ViewFlipper
android:id="#+id/vFlipper"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_above="#+id/textStatus"
android:layout_below="#+id/buttonSearch" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<ListView
android:id="#+id/lstVocab01"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
</ListView>
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<ListView
android:id="#+id/lstVocab02"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
</ListView>
</LinearLayout>
</ViewFlipper>
[...]
I inflate the same item layout inside both the ListView exploiting the same CursorAdapter (I am retrieving data from a database). Follows the item layout:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:id="#+id/textLine01"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/hello_world"
android:textSize="#dimen/text_big" />
<TextView
android:id="#+id/textLine02"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/app_name"
android:textSize="#dimen/text_normal" />
</LinearLayout>
As in the Main Layout, there is nothing that change styles or anything related. The adapter does nothing except inflating the DB fields inside the proper TextViews.
There is no difference in the way I update the two cursors. Given CursorAdapterVocabulary adapter_c; and CursorAdapterVocabulary adapter_e; correctly instantiated and correctly working.
adapter_c.changeCursor(cursor);
adapter_c.notifyDataSetChanged();
if (viewFlipper.getDisplayedChild() == 1) {
viewFlipper.setInAnimation(this, R.anim.in_from_left);
viewFlipper.setOutAnimation(this, R.anim.out_to_right);
viewFlipper.showPrevious();
}
[...]
adapter_e.changeCursor(cursor);
adapter_e.notifyDataSetChanged();
if (viewFlipper.getDisplayedChild() == 0) {
viewFlipper.setInAnimation(this, R.anim.in_from_right);
viewFlipper.setOutAnimation(this, R.anim.out_to_left);
viewFlipper.showNext();
}
But: the first ListView is well visibile. The second view has a sort of alpha transparency, which I couldn't remove even forcing alpha to 1.
Please not that:
The rest of the code works perfectly, ListView are updated every time with correct data
It is not a problem of ViewFlipper, I used to have this problem also when I did the runtime replacing of the ListView
I don't have this problem if I use the second ListView in another Activity
The issue is Android Version/Device independent (tried on Samsung SPlus 2.3.6, SIII 4+, Emulator 4.3.0)
This is an image of the difference between the two views, I am filling them with data from a Chinese Vocabulary:
I don't know anymore what to try. Please ask me more details if needed.
Related
I have added the ListView inside ViewPager, as soon as the page is loaded the first tab is selected and the last item of the list does not show up for the first time, its becoming visible when I go to next tab and come back. I would like to see all the items of the listview when its loaded for the first time. Please help me to fix this problem.
This is the xml for the listview -
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ListView
android:id="#+id/listview_categories"
android:layout_width="fill_parent"
android:divider="#color/light_gray_a1"
android:dividerHeight="0.667dp"
android:background="#color/white"
android:layout_height="fill_parent" />
</RelativeLayout>
add bottom padding like this and change fill_parent to match_parent
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ListView
android:id="#+id/listview_categories"
android:layout_width="match_parent"
android:divider="#color/light_gray_a1"
android:dividerHeight="0.667dp"
android:paddingBottom="40dp"
android:background="#color/white"
android:layout_height="match_parent" />
</RelativeLayout>
I had this issue. Just now I solved it. Look for android:layout_weight in all the Layouts you used and if it is set some non zero values like android:layout_weight="1" or android:layout_weight="0.91", then set them to zero like this,
android:layout_weight="0"
The empty text is showing even if the list is available .
I am tired finding the solution every where but nothing work for me
<?xml version="1.0" encoding="utf-8"?>
<com.cervo.222.view.ViewSwitcher xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/container"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<FrameLayout
android:id="#+id/item_container"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<TextView android:id="#android:id/empty"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="No Details found" />
</FrameLayout>
<FrameLayout
android:id="#+id/view_container"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
</com.cervo.222.view.ViewSwitcher>
Try something like this.
Create 2 views. First view is a TextView with the empty list message . Keep this TextView hidden initially (Visibility GONE). Second view is your Listview. Keep it visible. IN your onCreate or any appropriate method is activity or Fragment when you find that there is no data for List then make your ListView hidden and TextView visible.
I have an activity with the associated activity.xml code:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/pattern_background"
android:orientation="vertical" >
<ScrollView
android:id="#+id/scrollView"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_marginBottom="5dp"
android:layout_weight="1"
android:clickable="false" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
...
<LinearLayout
android:id="#+id/llComments"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:orientation="vertical" />
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView" />
</LinearLayout>
</ScrollView>
<include
android:id="#+id/layoutComments"
android:layout_width="match_parent"
android:layout_height="wrap_content"
layout="#layout/widget_comentarios_fragment" >
</include>
In the LinearLayout with id llComments I introduce a fragment called CommentsFragment dynamically from the activity with the following code:
private Fragment commentsFragment;
private FragmentTransaction ft;
...
llComentarios = (LinearLayout) findViewById(R.id.llComments);
...
Bundle args = new Bundle();
args.putString(Constants.IDMODEL, getId());
commentsFragment = CommentsFragment.newInstance(args);
ft = getSupportFragmentManager().beginTransaction();
ft.add(R.id.llComments, commentsFragment).commit();
The Fragment associated xml file is:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<ListView
android:id="#+id/comments"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:divider="#color/transparent"
android:dividerHeight="10dp"
android:paddingLeft="#dimen/indicator_internal_padding"
android:paddingRight="#dimen/indicator_internal_padding" />
</LinearLayout>
The problem I cannot solve is to show in the activity more than one item (in fact I am showing one and a third items) in the list if I do not fix a height for the listview.It should adapt to as many items I add to the list in the fragment through the adapter. I have tried different combinations of heights in the layouts and views, but still does not work. Maybe I am annulating one with other.
Any help would be appreciated.
Thanks in advance
After some days I find out the exact problem. I was including a ListView into a ScrollView, and that's clearly not recomended by Android developers.
You can look for further info here: Why ListView cannot be used in a ScrollView?
Anyway, if you want to do it, you can do that with a hack. Take a look at these proposals:
How can I put a ListView into a ScrollView without it collapsing?
For me that worked. Problem solved.
I'm having trouble designing a Activity.
I'm trying to use a Mvx.MvxBindableLinearLayout, making bind to a list: A, B and c;
When I do this binding, the result is:
A
B
C
C
B
A
The correct would be:
A
B
C
The code in question is:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:local="http://schemas.android.com/apk/res/m2uMobileSales.Droid"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:local="http://schemas.android.com/apk/res/m2uMobileSales.Droid"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:showDividers="none"
android:layout_weight="1">
<include
layout="#layout/PageCommon_Titlebar" />
<TableLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/tableLayout1"
android:divider="#null"
android:dividerHeight="0dp"
android:stretchColumns="1">
<TableRow
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/tableLayout1"
android:stretchColumns="1">
<!--Customer Name-->
<TextView
android:id="#+id/CustomerName"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textSize="30dp"
android:layout_weight="1"
local:MvxBind="{'Text':{'Path':'Customer.CustDetails.Name','Mode':'OneWay'}}" />
</TableRow>
<TableRow>
<!--Detail Pages android:padding="12dp" -->
<Mvx.MvxBindableLinearLayout
android:padding="3dip"
android:id="#+id/ClienteDetails"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:divider="#null"
android:dividerHeight="0dp"
android:orientation="vertical"
android:cacheColorHint="#00000000"
android:layout_weight="1"
local:MvxItemTemplate="#layout/listitem_clientdetailpages"
local:MvxBind="{'ItemsSource':{'Path':'DetailPageViewModels'}}"/>
<!--<Mvx.MvxBindableListView
android:id="#+id/ClienteDetails"
android:divider="#null"
android:dividerHeight="0dp"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:cacheColorHint="#00000000"
android:layout_weight="1"
local:MvxItemTemplate="#layout/listitem_clientdetailpages"
local:MvxBind="{'ItemsSource':{'Path':'DetailPageViewModels', 'Mode':'OneWay'}}" />-->
</TableRow>
</TableLayout>
</LinearLayout>
</ScrollView>
If I use commented Mvx.MvxBindableListView, I can only see the first item.
The objective is scroll all the elements and not the list, doing as the definitions of android.
After overcoming this problem, I will have a list within a list (DetailPageViewModels will have several elements including a list).
I've seen several posts that advise inserting all elements inside a ScrollView.
I tried comment Mvx.MvxBindableLinearLayout, ScrollView and MvxBindableListView worked well. If I use ScrollView I only see the first element.
My objective is use MvxBindableLinearLayout, because I need scroll the entire page, and and non elements.
listitem_clientdetailpages code:
<?xml version="1.0" encoding="utf-8" ?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:local="http://schemas.android.com/apk/res/m2uMobileSales.Droid"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:showDividers="none"
android:layout_weight="1">
<!--Page Title-->
<TextView
android:id="#+id/detailpagetitle"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:textSize="24dp"
android:padding="3dip"
local:MvxBind="{'Text':{'Path':'Title','Mode':'OneWay'}}" >
</TextView>
</LinearLayout>
I apologize for the confusion.
Thanks for the help and availability.
I just tried in v3 and this code worked as expected:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:local="http://schemas.android.com/apk/res/com.cirrious.dailydilbert"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<Mvx.MvxLinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
local:MvxBind="ItemsSource Items;ItemClick ItemSelectedCommand"
local:MvxItemTemplate="#layout/listitem_dilbert" />
</ScrollView>
I can't really see any problems in the LinearLayout for the code you've posted. It might help if I could see the template for the list item, and the viewmodel list itself. If you think there's a bug, then please post a simple reproduction somewhere and I'll look at it - the more full that reproduction the quicker I can look at it - i.e. ideally post a full solution on a github repo - I can just download and run it then.
For the bindable ListView I'd be a bit suspicious of the attribute android:layout_height="wrap_content" - suspect that might not work properly.
Update, I also tried in the Tutorial app, replacing the ListView with a LinearLayout in Page_MainMenuView.axml :
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:local="http://schemas.android.com/apk/res/Tutorial.UI.Droid"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<Mvx.MvxLinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
local:MvxBind="ItemsSource Items;ItemClick ShowItemCommand"
local:MvxItemTemplate="#layout/listitem_viewmodel"
/>
</ScrollView>
This displays perfectly - does this work also in your setup?
If it does, then the problem must be somewhere in the code you're not including...
I'm a coworker of Paulo Dias and we've just figured out what's happening...
The problem is in the creation of the MvxBindableLinearLayout
In the constructor we have
Adapter = new MvxBindableListAdapterWithChangedEvent(context);
Adapter.DataSetChanged += AdapterOnDataSetChanged;
And in the 'Set' of the property 'Adapter' we have
var existing = _adapter;
if (existing == value)
return;
if (existing != null && value != null)
{
existing.DataSetChanged -= AdapterOnDataSetChanged;
value.ItemsSource = existing.ItemsSource;
value.ItemTemplateId = existing.ItemTemplateId;
}
if (value != null)
{
value.DataSetChanged += AdapterOnDataSetChanged;
}
The first time the Adapter is created, the DataSetChanged event is subscribed two times (in the constructor and in the set of the adapter property).
This can be a problem if we have a notifiable collection binded to the MvxBindableLinearLayout.
Now the tricky part... This bug only 'reveals himself' when we do changes in the binded list after the ui control is created (i.e. add new items to the list). If we have a list in the viewmodel that is 'setted in the constructor' and then is never changed, the DataSetChanged event will never be fired. On the other hand, if we add items after the ui is created (i.e. you can have a command binded to a button, that adds items to the list), the items will be duplicated in the ui...
To solve this, we´ve just commented the line in the MvxBindableLinearLayout contructor where the DataSetChanged` is beeing subscribed, and all falls back to place :)
public MvxBindableLinearLayout(Context context, IAttributeSet attrs)
: base(context, attrs)
{
var itemTemplateId = MvxBindableListViewHelpers.ReadAttributeValue(context, attrs,
MvxAndroidBindingResource.Instance
.BindableListViewStylableGroupId,
MvxAndroidBindingResource.Instance
.BindableListItemTemplateId);
Adapter = new MvxBindableListAdapterWithChangedEvent(context);
Adapter.ItemTemplateId = itemTemplateId;
//Adapter.DataSetChanged += AdapterOnDataSetChanged;
this.ChildViewRemoved += OnChildViewRemoved;
}
Hope this can help!
ps: Wondering why anyone didn't had this problem before...
ps1: We are currently using MvvmCross vNext.
ps2: I've changed to Mvvmcross V3, and the problem persists. I'll make a request in Github
I have requirement like play store app where there is view pager with images and videos
and scroll to view details .Unfortunately when user scrolls the scroll is jumpy but if i remove the scrollview the view pager works perfectly fine .
The layout look and feel is something like this
http://cl.ly/MBRB
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" android:fillViewport="true">
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="160dp"
android:background="#drawable/loading_image"
android:gravity="top"
android:orientation="vertical" >
<android.support.v4.view.ViewPager
android:id="#+id/product_image_pager"
android:layout_width="fill_parent"
android:layout_height="match_parent" />
<com.viewpagerindicator.CirclePageIndicator
android:id="#+id/titles"
style="#style/CirclePageIndicator"
android:layout_alignParentBottom="true"
android:padding="10dip"
android:paddingBottom="10dp" />
</RelativeLayout>
<include layout="#layout/app_screen_menu" />
</LinearLayout>
</ScrollView>
Btw i am loading images from server .
Thanks
You are using 2 scrollisteners
A viewpager uses a scrolllistener
A scrollview uses a scrolllistener
These two scrollistener are fighting for the ScrollEvent.
You can solve this by implementing onInterceptTouch. In this method you can decide who wins the fight over the ScrollEvent
Take a look at this protected post regarding a similair issue containing 2 scrollviews