I need to put one listview with cursorloader above and down one litsview with static data. This is my layout
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fillViewport="true" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="10dip"
android:orientation="vertical">
<TextView
android:id="@+id/header_mi_facultad"
android:text="@string/header_list_mi_facultad"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:minHeight="?android:attr/listPreferredItemHeight"
android:textStyle="bold"
android:textSize="22sp"
android:textColor="#FFFFFF"
android:padding="10dp"
android:background="#336699"
/>
<ListView
android:id="@+id/list_view"
android:layout_width="match_parent"
android:layout_height="wrap_content">
</ListView>
<TextView
android:id="@+id/header_textview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dip"
android:gravity="center_vertical"
android:minHeight="?android:attr/listPreferredItemHeight"
android:text="@string/header_list_servicios"
android:textStyle="bold"
android:textSize="22sp"
android:textColor="#FFFFFF"
android:padding="10dp"
android:background="#336699"
/>
<ListView
android:id="@+id/list_servicios"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:entries="@array/servicios_array"
>
</ListView>
</LinearLayout>
the snippet of the fragment where i set the adapters
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
Log.d(LOG_TAG, "---Se creo la vista del MainActivityFragment---");
View rootView = inflater.inflate(R.layout.list_main, container, false);
ListView listView = (ListView) rootView.findViewById(R.id.list_view);
listServiciosView = (ListView) rootView.findViewById(R.id.list_servicios);
serviciosAdapter = new ArrayAdapter<String>(getActivity(), R.layout.list_item, servicios);
listServiciosView.setAdapter(serviciosAdapter);
menuAdapter = new MenuAdapter(getActivity(), null, 0);
listView.setAdapter(menuAdapter);
ListUtils.setDynamicHeight(listView);
ListUtils.setDynamicHeight(listServiciosView);
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Cursor cursor = (Cursor) parent.getItemAtPosition(position);
int index = cursor.getColumnIndex(AppContract.MenuEntry.COLUMN_TYPE);
int type = cursor.getInt(index);
Intent intent;
Log.d(LOG_TAG, "id : " + id + " position : " + position);
Log.d(LOG_TAG, "tipo : " + type);
switch (type) {
case NOTICIA_LISTA:
index = cursor.getColumnIndex(AppContract.MenuEntry._ID);
Long idMenu = cursor.getLong(index);
Log.d(LOG_TAG, "url : " + idMenu);
intent = new Intent(view.getContext(), ListActivity.class);
intent.putExtra("idSolicitado", idMenu);
intent.putExtra("idOrigen", 0);
startActivity(intent);
break;
case NOTICIA_URL:
index = cursor.getColumnIndex(AppContract.MenuEntry.COLUMN_URL);
String url = cursor.getString(index);
Log.d(LOG_TAG, "url : " + url);
intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse(url));
startActivity(intent);
break;
case SERVICIO_CUOTA:
intent = new Intent(view.getContext(), PayActivity.class);
startActivity(intent);
break;
default:
Log.d(LOG_TAG, "Nada!!!");
break;
}
}
});
listServiciosView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Intent intent;
Log.d(LOG_TAG, "id : " + id + " position : " + position);
switch (position) {
case 0:
intent = new Intent(view.getContext(), PayActivity.class);
startActivity(intent);
break;
default:
Log.d(LOG_TAG, "Nada!!!");
break;
}
}
});
return rootView;
}
the utility class that i tried
public static class ListUtils {
public static void setDynamicHeight(ListView mListView) {
ListAdapter mListAdapter = mListView.getAdapter();
if (mListAdapter == null) {
// when adapter is null
return;
}
int height = 0;
int desiredWidth = View.MeasureSpec.makeMeasureSpec(mListView.getWidth(), View.MeasureSpec.UNSPECIFIED);
for (int i = 0; i < mListAdapter.getCount(); i++) {
View listItem = mListAdapter.getView(i, null, mListView);
listItem.measure(desiredWidth, View.MeasureSpec.UNSPECIFIED);
height += listItem.getMeasuredHeight();
}
ViewGroup.LayoutParams params = mListView.getLayoutParams();
params.height = height + (mListView.getDividerHeight() * (mListAdapter.getCount() - 1));
mListView.setLayoutParams(params);
mListView.requestLayout();
}
}
Here are the screenshots url sc1 sc2 it works with portrait orientation, but with landscape the firts listview only show the firts element. I want to show all the elements in it. How i can do that? I tried this here and it works with static data but in my case have the problem explained. Is there a problem with the cursor loader? or i miss something in the layout?