C
C
Chvalov2015-10-16 09:27:50
Java
Chvalov, 2015-10-16 09:27:50

ListView does not display the last element in the list, even though it is there 100%, how to deal with it?

There is a view sheet, here is the code:

public class EditingFragment extends Fragment { 
    private ListView mListView;

    public static EditingFragment newInstance(String param1, String param2) { 
        EditingFragment fragment = new EditingFragment();
        Bundle args = new Bundle();
        args.putString(ARG_PARAM1, param1);
        args.putString(ARG_PARAM2, param2);
        fragment.setArguments(args);
        return fragment;
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        View view = inflater.inflate(R.layout.fragment_editing, container, false);

        mListView = (ListView) view.findViewById(R.id.SensorSetpointList); // заебись название вьюзи EnterPays_atomPaysList
        mListView.setAdapter(new ListViewAdapter(getActivity(), R.layout.sensor_setpoint_list_item, new Byte[]{1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20})); 

        return view;
    }

    class ListViewAdapter extends ArrayAdapter<Byte> {
        private Byte[] items;
        private int layoutResourceId;
        private Context context;

        public ListViewAdapter(Context context, int layoutResourceId, Byte[] items) {
            super(context, layoutResourceId, items);
            this.layoutResourceId = layoutResourceId;
            this.context = context;
            this.items = items;
        }

        @Override
        public int getCount() {
            return items.length;
        }

        @Override
        public View getView(int position, View view, ViewGroup parent) {
            if(view == null){
                view = getActivity().getLayoutInflater().inflate(layoutResourceId, parent, false);
            }

            EditText data = (EditText) view.findViewById(R.id.ET_SensorSetpointDefault);
            data.setText(""+items[position]);

            return view;
        }
    }

As a result, I should see: 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20
But I display the maximum 19, and I can only get to 20 when I open the text field at 19 and press the next button, but even after that I don't see it on the screen.
1603d55584094f96af6d9d04f970e46d.png
If you pull to the very top, a blue shadow appears a bit (I don’t know what it’s called exactly), you can see in the picture
Here is my XML fragment:
<FrameLayout 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="ua.com.ovis.andrey.calibrationforsensors.EditingFragment">

    <!-- TODO: Update blank fragment layout -->
    <LinearLayout
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <LinearLayout
            android:orientation="horizontal"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="0">

            <Button
                android:id="@+id/EnterPays_addAtomPayment"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_centerHorizontal="true"
                android:layout_alignParentTop="true"
                android:text="TEXT"
                android:drawableLeft="@android:drawable/ic_menu_save" />

            <Button
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="New Button"
                android:id="@+id/button"
                android:drawableLeft="@android:drawable/ic_menu_sort_by_size" />
        </LinearLayout>

        <ListView
            android:id="@+id/SensorSetpointList"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight="1"
            tools:listitem="@layout/sensor_setpoint_list_item">

        </ListView>

    </LinearLayout>

</FrameLayout>
And here is the XML ListView itself
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="horizontal" >

    <!--  Здесь ID жлемента от 0 -->
    <TextView
        android:layout_width="100dp"
        android:layout_height="fill_parent"
        android:id="@+id/TV_SensorSetpointIndex"
        android:textStyle="bold"
        android:gravity="center" />

    <!--  Здесь данные с массива -->
    <EditText
        android:id="@+id/ET_SensorSetpointDefault"
        android:layout_width="0sp"
        android:layout_height="fill_parent"
        android:layout_weight="2"
        android:gravity="center_vertical"
        android:textAppearance="?android:attr/textAppearanceSmall"
        android:editable="false"
        android:imeOptions="actionDone"
        android:inputType="none" />

    <EditText
        android:id="@+id/ET_SensorSetpointNew"
        android:layout_width="0sp"
        android:layout_height="fill_parent"
        android:layout_weight="1"
        android:gravity="center"
        android:imeOptions="actionDone"
        android:inputType="numberDecimal"
        android:textAppearance="?android:attr/textAppearanceSmall" />

    <ImageButton
        android:id="@+id/Btn_SensorSetpointClear"
        android:layout_width="wrap_content"
        android:layout_height="fill_parent"
        android:contentDescription="@string/app_name"
        android:onClick="removeAtomPayOnClickHandler"
        android:src="@android:drawable/ic_menu_delete" />
</LinearLayout>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
C
Chvalov, 2015-10-16
@Chvalov

belozerow : The whole problem was in
the activity, it uses a new android.support.design.widget.CoordinatorLayout which turned out to be crooked :(
I don’t know who to write to correct it and whether it should be written, maybe it should work like that, but that’s not the point.
I changed it to LinearLayout

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/main_content"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    tools:context="ua.com.ovis.andrey.calibrationforsensors.SensorsCalibrationFirstActivity"
    android:orientation="vertical">

    <android.support.design.widget.AppBarLayout android:id="@+id/appbar"
        android:layout_width="match_parent" android:layout_height="wrap_content"
        android:paddingTop="@dimen/appbar_padding_top"
        android:theme="@style/AppTheme.AppBarOverlay">

        <android.support.v7.widget.Toolbar android:id="@+id/toolbar"
            android:layout_width="match_parent" android:layout_height="?attr/actionBarSize"
            android:background="?attr/colorPrimary" app:popupTheme="@style/AppTheme.PopupOverlay"
            app:layout_scrollFlags="scroll|enterAlways"/>

        <android.support.design.widget.TabLayout android:id="@+id/tabs"
            android:layout_width="match_parent" android:layout_height="wrap_content" />

    </android.support.design.widget.AppBarLayout>

    <android.support.v4.view.ViewPager android:id="@+id/container"
        android:layout_width="match_parent" android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior" />

</LinearLayout>
And everything works like clockwork ))

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question