на самом деле у меня следующая проблема:
У меня два ListView загружаются автоматически с двумя адаптерами, проблема в XML, в обоих списках отображается только первый элемент.
вот мой xml-код:
<?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"
tools:context = "com.example.hrizi.onescore.home_links.searshscore">
<include
android:id = "@+id/toolbar"
layout = "@layout/apptoolbar"
android:layout_width = "match_parent"
android:layout_height = "wrap_content"
android:layout_centerHorizontal = "true"
android:scaleType = "fitCenter" />
<ScrollView
android:layout_width = "match_parent"
android:layout_height = "wrap_content"
android:layout_marginTop = "66dp"
android:fillViewport = "true">
<LinearLayout
android:id = "@+id/ll1"
android:layout_width = "match_parent"
android:layout_height = "wrap_content"
android:orientation = "vertical">
<LinearLayout
android:id = "@+id/ll"
android:layout_width = "match_parent"
android:layout_height = "wrap_content"
android:orientation = "vertical">
<EditText
android:id = "@+id/sv_search"
android:layout_width = "match_parent"
android:layout_height = "50dp"
android:layout_marginLeft = "20dp"
android:layout_marginRight = "20dp"
android:background = "@drawable/edittextbackground"
android:hint = "Search ..."
android:inputType = "text"
android:textAlignment = "center"></EditText>
<Button
android:id = "@+id/btn_search"
android:layout_width = "match_parent"
android:layout_height = "wrap_content"
android:layout_marginLeft = "20dp"
android:layout_marginTop = "10dp"
android:layout_marginRight = "20dp"
android:layout_weight = "1"
android:background = "@color/coloronscore"
android:onClick = "btnsearchOnClick"
android:text = "Search"
android:textAllCaps = "false"
android:textColor = "@color/colorwhite" />
</LinearLayout>
<!--Result of research-->
<ListView
android:id = "@+id/listView1"
android:layout_width = "match_parent"
android:layout_height = "248dp"
android:layout_marginTop = "10dp"
android:layout_weight = "1"
android:paddingBottom = "5dp" />
<ListView
android:id = "@+id/listView"
android:layout_width = "match_parent"
android:layout_height = "248dp"
android:layout_marginTop = "10dp"
android:layout_weight = "1"
android:paddingBottom = "5dp" />
</LinearLayout>
</ScrollView>
</RelativeLayout>
проблема я думаю в ScrollView или еще что смывает к тому.
заранее спасибо .
Итак, какое решение, пожалуйста, @Yupi
@hatemdagbouj зачем вы используете два ListView? Почему бы не использовать только 1 ListView?




Вы можете использовать эту функцию для отображения всех элементов в списке.
public static void setListViewHeightBasedOnChildren(ListView listView) {
ListAdapter listAdapter = listView.getAdapter();
if (listAdapter == null) {
// pre-condition
return;
}
int totalHeight = 0;
int desiredWidth = MeasureSpec.makeMeasureSpec(listView.getWidth(), MeasureSpec.AT_MOST);
for (int i = 0; i < listAdapter.getCount(); i++) {
View listItem = listAdapter.getView(i, null, listView);
listItem.measure(desiredWidth, MeasureSpec.UNSPECIFIED);
totalHeight += listItem.getMeasuredHeight();
}
ViewGroup.LayoutParams params = listView.getLayoutParams();
params.height = totalHeight + (listView.getDividerHeight() * (listAdapter.getCount() - 1));
listView.setLayoutParams(params);
listView.requestLayout();
}
Пример:
setListViewHeightBasedOnChildren(yourlistview);
Потому что вы используете
ListViewвнутриScrollView