2015-06-01 3 views
0

Я новичок в списках android listviews, и я пытаюсь заполнить список в андроиде списком элементов, поступающих из webservice. Я знаю, что список содержит более одной записи, поступающей из webservice, но в моем пользовательском listview отображается только первая запись из списка. Я проверил размер списка и всегда есть несколько записей, но в списке есть только один из них. Мой заказ адаптер, как следующее:Listview отображает только одну строку из списка

public class ListAdapter extends BaseAdapter { 
    Context ctx; 
    LayoutInflater lInflater; 
    ArrayList<LItem> lstItems; 

    ListAdapter(Context context, ArrayList<LItem> objects) { 
     ctx = context; 
     lstItems = objects; 
     lInflater = (LayoutInflater) ctx 
       .getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
    } 

    @Override 
    public int getCount() { 
     return lstItems.size(); 
    } 

    @Override 
    public Object getItem(int position) { 
     return lstItems.get(position); 
    } 

    @Override 
    public long getItemId(int position) { 
     return position; 
    } 

    @Override 
    public View getView(int position, View convertView, ViewGroup parent) { 
     View view = convertView; 
     if (view == null) { 
      view = lInflater.inflate(R.layout.list_style_task 
        , parent, false); 
     } 

     LItem p = getProduct(position); 

     ((TextView) view.findViewById(R.id.tvMaterial)).setText(p.getMName()); 
     ((TextView) view.findViewById(R.id.tvTask)).setText(p.getTName()); 
     ((TextView) view.findViewById(R.id.tvBQuantity)).setText(p.getBQ()); 

    // CheckBox cbBuy = (CheckBox) view.findViewById(R.id.checkbox); 
     //cbBuy.setOnCheckedChangeListener(myCheckChangList); 
    // cbBuy.setTag(position); 
    // cbBuy.setChecked(p.selected); 
     return view; 
    } 

    LItem getProduct(int position) 
    { 
     return ((LItem) getItem(position)); 
    } 

    ArrayList<LItem> getBox() { 
     ArrayList<LItem> box = new ArrayList<LItem>(); 
     for (LItem p : lstItems) { 
     // if (p.selected) 
      // box.add(p); 
     } 
     return box; 
    } 

    OnCheckedChangeListener myCheckChangList = new OnCheckedChangeListener() { 
     public void onCheckedChanged(CompoundButton buttonView, 
       boolean isChecked) { 
      //getProduct((Integer) buttonView.getTag())= isChecked; 
     } 
    }; 
} 

Я, связывающий ListView как:

protected void onPostExecute(List<LItem> li) { 
      super.onPostExecute(lstItm); 
      if(lstItm.size()>0) { 

       Adp=new ListAdapter(myactivity,lstItm); 

       lvTasks.setAdapter(Adp); 

       Log.d("Size---------",Integer.toString(lstItm.size()));//here it writes more than one as size of the list. 

    } 
} 

Мой файл XML для отображения списков, как это:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" android:layout_height="match_parent" 
    android:orientation="vertical" 


    > 
    <LinearLayout 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:orientation="horizontal" 
     android:layout_marginLeft="20dp" 
     android:layout_marginRight="20dp" 

     > 
     <CheckBox 
      android:id="@+id/checkBox1" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_alignParentLeft="true" 
      android:focusable="false" 
      android:textColor="#FFF" 
      android:button="@drawable/custom_checkbox_design" 

      android:focusableInTouchMode="false" 
      android:text="" /> 
     <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="Task:" 
      android:id="@+id/textView2" 
      android:layout_weight="1" 
      android:textColor="#FFF" 
      /> 
     <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="task" 
      android:id="@+id/tvTask" 
      android:layout_weight="1" 
      android:textColor="#FFF" 
      /> 


     </LinearLayout> 

    <LinearLayout 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_marginLeft="45dp" 
     android:layout_marginRight="20dp" 
     > 

     <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="Material:" 
      android:id="@+id/textView1" 
      android:layout_weight="1" 
      android:textColor="#FFF" 
      /> 
     <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="material" 
      android:id="@+id/tvMaterial" 
      android:layout_weight="1" 
      android:textColor="#FFF" 
      /> 


    </LinearLayout> 

    <LinearLayout 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:orientation="horizontal" 
     android:layout_marginLeft="45dp" 
     android:layout_marginRight="20dp" > 
     <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="Balanced Quantity:" 
      android:id="@+id/textView14" 
      android:layout_weight="1" 
      android:textColor="#FFF" 
      /> 
     <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="bquantity" 
      android:id="@+id/tvBQuantity" 
      android:layout_weight="1" 
      android:textColor="#FFF" 
      /> 


    </LinearLayout> 
    <LinearLayout 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_marginLeft="45dp" 
     android:layout_marginRight="20dp"> 

     <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="Adjust Balanced Quantity:" 
      android:id="@+id/textView25" 
      android:layout_weight="1" 
      android:textColor="#FFF" 
      /> 
     <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="" 
      android:id="@+id/tvAQuantity" 
      android:layout_weight="1" 
      android:textColor="#FFF" 
      /> 

     </LinearLayout> 


</LinearLayout> 

Мой XML для ListView является например:

<LinearLayout 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="kanix.highrise.com.highrise.generate_material_requisition"> 

    <!-- TODO: Update blank fragment layout --> 
    <ScrollView android:id="@+id/ScrlView" android:layout_width="fill_parent" android:layout_height="fill_parent" > 
<LinearLayout 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:orientation="vertical" 
    > 
    <ListView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:id="@+id/lstTaskQuantity" 
     android:layout_weight="1" > 


     </ListView> 



     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_margin="10dp"> 
      <TextView 
       android:id="@+id/txtLddsdfabel" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_centerInParent="true" 
       android:textSize="16dp" 
       android:text="Req. From :" 
       android:layout_weight="1" 
       android:textColor="#fff" /> 

      <EditText 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:inputType="date" 

       android:id="@+id/etDate" 
       android:layout_weight=".5" 

       android:hint="DD/MM/YYYY"/> 

      <ImageButton 
       android:layout_width="35dp" 
       android:layout_height="35dp" 
       android:id="@+id/btnimgcal" 


       android:src="@drawable/calender" 
       /> 


     </LinearLayout> 



     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_margin="10dp"> 
      <TextView 
       android:id="@+id/txtLddsdfadsbel" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_centerInParent="true" 
       android:textSize="16dp" 
       android:text="For Days :" 
       android:layout_weight="1" 
       android:textColor="#fff" /> 

      <EditText 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:inputType="number" 
       android:text="0" 

       android:id="@+id/editText" 
       android:layout_weight="1.69" /> 


     </LinearLayout> 

     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_margin="10dp"> 
      <TextView 
       android:id="@+id/txtLddsddfgfadsbel" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_centerInParent="true" 
       android:textSize="16dp" 
       android:text="Quantity :" 
       android:layout_weight="1" 
       android:textColor="#fff" /> 

      <EditText 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:inputType="number" 
       android:text="0" 

       android:id="@+id/etQuantity" 
       android:layout_weight="1.60" /> 


     </LinearLayout> 

     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_margin="10dp" 
      android:layout_gravity="center" 
      android:orientation="vertical" 
      > 







      <Button 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       android:textColor="#0080FF" 
       android:background="#fff" 
       android:text="Generate Requisition" 
       android:id="@+id/btnSave" /> 





     </LinearLayout> 




</LinearLayout> 



    </ScrollView> 
</LinearLayout> 
+0

разместить свой файл XML –

+0

опубликовать фрагмент кода, где вы Наполнение '' Список Blackbelt

+0

@Nilesh плз увидеть мой отредактированный вопрос ... @ Список Blackbelt заполнен правильно. Я проверил размер, который был больше 1. – killer

ответ

0

Проблема была связана с прокруткой, которая создавала проблему. Я только что удалили

<ScrollView android:id="@+id/ScrlView" android:layout_width="fill_parent" android:layout_height="fill_parent" > 


</ScrollView> 

и он работал для меня :)