-1

List view is not showing anything when i dont add any delay in code but when i add delay for about 1 second ,the results of list view gets displayed on screen.Its working in android version 5.1 in this way but when i run code in android 7.1 nougat it doesnt show anything on the screen while the data is being received from the server as i can see it by toasting.

Entry1.xml (the custom adapter)

<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:orientation="horizontal"
    android:padding="13dp"

    android:focusable="false"
    android:focusableInTouchMode="false"


    >

<ImageView
    android:layout_width="90dp"
    android:layout_height="50dp"
    android:src="@drawable/image"
    android:layout_gravity="center"

    android:focusable="false"
    android:focusableInTouchMode="false"
    />

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical"

    android:focusable="false"
    android:focusableInTouchMode="false"
    >

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="horizontal"

        android:focusable="false"
        android:focusableInTouchMode="false">


        <TextView
            android:layout_width="100dp"
            android:layout_height="match_parent"
            android:text="Name"
            android:textAlignment="center"
            android:textColor="@color/black"
            android:textSize="14dp"

            android:focusable="false"
            android:focusableInTouchMode="false"/>


    <TextView
        android:id="@+id/name2"
        android:layout_width="150dp"
        android:layout_height="wrap_content"
        android:textAlignment="center"
        android:layout_marginLeft="15dp"
        android:background="#00000000"
        android:letterSpacing="0.1"
        android:textSize="16dp"
        android:inputType="text"
        android:textColor="@color/black"

        android:focusable="false"
        android:focusableInTouchMode="false"
        />




    </LinearLayout>


    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="horizontal"

        android:focusable="false"
        android:focusableInTouchMode="false">

        <TextView
            android:layout_width="100dp"
            android:layout_height="match_parent"
            android:text="Company Name"
            android:textColor="@color/black"
            android:textSize="14dp"
            android:textAlignment="center"

            android:focusable="false"
            android:focusableInTouchMode="false"/>

    <TextView
        android:id="@+id/cname2"
        android:layout_width="150dp"
        android:layout_height="wrap_content"
        android:textAlignment="center"
        android:layout_marginLeft="15dp"
        android:background="#00000000"
        android:letterSpacing="0.1"
        android:textSize="16dp"
        android:inputType="text"
        android:textColor="@color/black"

        android:focusable="false"
        android:focusableInTouchMode="false"
        />

        </LinearLayout>



    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="horizontal"

        android:focusable="false"
        android:focusableInTouchMode="false">


        <TextView
            android:layout_width="100dp"
            android:layout_height="match_parent"
            android:text="Position"
            android:textColor="@color/black"
            android:textSize="14dp"
            android:textAlignment="center"

            android:focusable="false"
            android:focusableInTouchMode="false"/>



    <TextView
        android:id="@+id/pos2"
        android:layout_width="150dp"
        android:layout_height="wrap_content"
        android:textAlignment="center"

        android:layout_marginLeft="15dp"
        android:background="#00000000"
        android:letterSpacing="0.1"
        android:textSize="16dp"
        android:inputType="text"
        android:textColor="@color/black"

        android:focusable="false"
        android:focusableInTouchMode="false"
        />

        </LinearLayout>

</LinearLayout>

Card.xml (the main activity )

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/rlLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.hppc.business.Card">

<ListView
    android:id="@+id/lvUsers"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentTop="true"
    android:layout_alignParentLeft="true"
    android:layout_alignParentStart="true"
    android:clickable="true"
    android:focusable="false"
    android:focusableInTouchMode="false"
    android:descendantFocusability="blocksDescendants">

</ListView>

The mainactivity.java

 protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    employee_id = getIntent().getStringExtra("employee_id");
    //Toast.makeText(getApplicationContext(),answer,Toast.LENGTH_SHORT).show();
    requestQueue1 = Volley.newRequestQueue(this);

    doit_function();

    setContentView(R.layout.activity_card);
    listView = (ListView) findViewById(R.id.lvUsers);
    listView.setClickable(true);



    populateUsersList();
}

1 Answers1

1

Use RecyclerView istead of listView.

 recyclerView = (RecyclerView) findViewById(R.id.ur_view);
    LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false);
    recyclerView.setLayoutManager(linearLayoutManager);
    recyclerView.setItemAnimator(new DefaultItemAnimator());
    recyclerView.setHasFixedSize(true);

Set your adapter into recyclerview with the condition you want, either its local db or server.

urvi joshi
  • 158
  • 13
  • I tried the Recycler view as well it also has the same problem. – himanshu Jul 03 '17 at 06:39
  • 1
    Try to add static values first and see the result, success or not? @himanshu – urvi joshi Jul 03 '17 at 07:03
  • with static data it works in listview as well as recycler view but when I try fetching the data from the server none of them work. Another strange thing I observed is that if I open the camera Intent and close it the data appears on the screen. – himanshu Jul 12 '17 at 02:48
  • I tried adding a refresh button and when I click on the the refresh button then also the data is appearing ??? – himanshu Jul 12 '17 at 02:58
  • 1
    i think there is no problem with your recycler view or list view , there is problem with fetching data from server @himanshu – urvi joshi Jul 12 '17 at 06:02
  • 1
    Thanks a lot solved it just had to make call to the populate list view function after parsing the JSON rather than calling it in onCreate . Thank You for all Your help ! – himanshu Jul 12 '17 at 06:08