android


Android auto merge two listview in one screen


My view look like:
<?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" >
<!--list 1-->
<ListView
android:id="#+id/lvMenu"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:cacheColorHint="#android:color/transparent"
android:layout_marginBottom="10dp" />
<!--the header-->
<LinearLayout
android:id="#+id/llIndustries"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/dark_grey_title_bar"
android:paddingBottom="5dp"
android:paddingLeft="10dp"
android:paddingTop="5dp" >
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="#string/industry_clusters"
android:textSize="16sp"/>
</LinearLayout>
<!--list 2-->
<ListView
android:id="#+id/lvIndustries"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:cacheColorHint="#android:color/transparent" />
</LinearLayout>
I use two custom adapter to display two list view (the listview data source completely different each other):
private List<MenuInfo> menuData;
private List<MenuInfo> industriesData;
lvMenu = (ListView) layoutRoot.findViewById(R.id.lvMenu);
lvIndustries = (ListView) layoutRoot.findViewById(R.id.lvIndustries);
menuAdapter = new MenuAdapter(getActivity(), menuData);
lvMenu.setAdapter(menuAdapter);
industriesAdapter = new MenuAdapter(getActivity(), industriesData);
lvIndustries.setAdapter(industriesAdapter);
What I expect is:
<ListView/> <!-- listview 1-->
<TextView/> <!-- header-->
<ListView/> <!-- listview 2-->
But the problem is two list view auto merged into one ListView, and the header TextView disappear (If has one ListView, the header will be showed).
I have no idea for this issue. Could you please tell me where I am wrong?
Try the below example:
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"
android:weightSum="3" >
<ListView
android:id="#+id/list2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#drawable/face"
android:cacheColorHint="#00000000" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_weight="1"
android:orientation="vertical" >
<TextView
android:id="#+id/text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Header"
android:visibility="visible" />
<ListView
android:id="#+id/list"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/background"
android:cacheColorHint="#00000000" />
</LinearLayout>
</LinearLayout>
In your class
ListViewAdapter arrayAdapter = new ListViewAdapter(this, values);
listview.setAdapter(arrayAdapter);
ListViewAdapter arrayAdapter2 = new ListViewAdapter(this, values2);
listview2.setAdapter(arrayAdapter2);
Add these two lines in onCreate with your listview:
Utility.setListViewHeightBasedOnChildren(listview);
Utility.setListViewHeightBasedOnChildren(listview2);
Create a inner class in your Activity:
//Test scrollview custom
public static class Utility {
public static void setListViewHeightBasedOnChildren(ListView listView) {
ListAdapter listAdapter = listView.getAdapter();
if (listAdapter == null) {
// pre-condition
return;
}
int totalHeight = 0;
for (int i = 0; i < listAdapter.getCount(); i++) {
View listItem = listAdapter.getView(i, null, listView);
listItem.measure(0, 0);
totalHeight += listItem.getMeasuredHeight();
}
ViewGroup.LayoutParams params = listView.getLayoutParams();
params.height = totalHeight + (listView.getDividerHeight() * (listAdapter.getCount() - 1));
listView.setLayoutParams(params);
}
}
Code taken from : listViewNotScrolling
It would definitely work! :)
If you want to create Listview with Header. Then Use Section Header Listview.
Refer this Example.
Hope it will help you!!
OR
If its fix that Only Two Listview & one Header Between them
Then
1) Take Only one Listview.
2) Use Custom Adapter & Custom Layout for Listview Row.
3) Add Two Extra TextView in Custom Layout
Listing First ListView Data
(Fixed TextView - Header -Put its Visibility VISIBLE)
(Extra 1 TextView - Header -Put its Visibility GONE )
(Extra 2 TextView - Header -Put its Visibility GONE )
Listing Second ListView Data
(Fixed TextView - Header -Put its Visibility GONE )
(Extra 1 TextView - Header -Put its Visibility VISIBLE )
(Extra 2 TextView - Header -Put its Visibility VISIBLE )

Related Links

Recycler View on Scroll Stop
The difference between onClick and clickListener
Display two specified Activity when the specified user's first time login
Downloadable Android app themes
Runnable in Fragment runs faster after Resume
Hide toolbar on scroll inside BottomSheet view
Install an Android SDK Package through CLI if not Installed
ItemTouchHelper: How to prevent “fling” swipes until finger passes swipe threshold?
How to close foreground app in Android service?
How to pull layouts similar to elastic type when scrolling android?
how to gettext in listview
Sending and receiving data between devices in android over wifi connection
Android SSLSocket#getInputstream() throws HandshakeException on earlier versions of Android 6.0
Fabric Android - Force Login
validate google places autocomplete input in android
How to put this imageView in this place? - Android

Categories

HOME
grok
localization
telegram
nvd3.js
object
angular-formly
saml-2.0
composite-primary-key
vscode-extensions
mips
visual-studio-emulator
jtextpane
spin
augeas
jquery-ui-sortable
mautic
line
google-form
supervisor
symbol
keytool
null-pointer
googlebot
user-experience
imagemap
jboss6.x
syntax-highlighting
android-sharedpreferences
shared
paperjs
calculation
google-cast
panoramas
quickfixj
spring-security4
indy10
reverse
arduino-ide
mnist
apiary.io
openproject
cd
recurrent-neural-network
linq-to-objects
doc
plaintext
android-ibeacon
tcc
uiimage
getchar
dynamic-linq
textsum
gitlist
sonarlint-eclipse
openblas
remedy
pair-programming
spring-data-couchbase
quicktime
seq
template-toolkit
testrail
chromium-os
node-request
pre-build-event
nservicebus5
decimalformat
xenomai
xvim
node-serialport
android-broadcast
j-security-check
shopizer
public-html
variadic-templates
wcm
ss7
codeplex
reflector
lnk
xml-dsig
isqlquery
pagedown
server-administration
robotlegs
qtconcurrent
objectquery
multiplexing
objective-j
instantiationexception
facebook-iframe
object-database
easyb
scrollbars
build-environment
mathematical-notation
complex-event-processing
dojo-dnd
java1.4

Resources

Encrypt Message