2017-06-27 3 views
-1

Listenansicht zeigt nichts, wenn ich keine Verzögerung im Code hinzufügen, aber wenn ich Verzögerung für ca. 1 Sekunde hinzufügen, wird die Ergebnisse der Listenansicht auf dem Bildschirm angezeigt.Ist in Android-Version 5.1 arbeiten auf diese weise, aber wenn ich code in android 7.1 nougat es zeigt nichts auf dem bildschirm, während die daten vom server empfangen werden, wie ich es durch toasten sehen kann.Listenansicht funktioniert nicht richtig in android

Entry1.xml (die individuelle 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 (die Haupttätigkeit)

<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> 

Die 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(); 
} 

Antwort

1

Verwenden Sie RecyclerView anstelle von 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); 

Ihr Adapter in recyclerview mit der Bedingung Stellen Sie wollen, entweder seine lokale db oder Server.

+0

Ich habe die Recycler-Ansicht versucht, es hat auch das gleiche Problem. – himanshu

+1

Versuchen Sie zuerst statische Werte hinzuzufügen und sehen Sie das Ergebnis, Erfolg oder nicht? @himanshu –

+0

mit statischen Daten funktioniert es in Listview sowie Recycler-Ansicht, aber wenn ich versuche, die Daten vom Server abrufen, keiner von ihnen funktioniert. Eine andere seltsame Sache, die ich beobachtete, ist, dass wenn ich die Kamera Intent öffne und es schließe, die Daten auf dem Schirm erscheinen. – himanshu

Verwandte Themen