xml - Android custom row layout not showing up in listview -


i can't see row i've added list view , wondering if has layout or listviewadapter. in debug can see array filled data passed arraylist playerlist, , see data in toast nothing shows on screen. mainactivity xml:

<?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="vertical" >      <textview         android:layout_width="fill_parent"         android:layout_height="wrap_content"         android:text="@string/txtv_battingorder_title"         android:textsize="20sp" />      <button         android:id="@+id/button1"         style="?android:attr/buttonstylesmall"         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:text="@string/btn_addbutton_title" />      <listview         android:id="@+id/list"         android:layout_width="fill_parent"         android:layout_height="0dp"         android:layout_weight="0.89" >     </listview>  </linearlayout> 

new row layout:

<?xml version="1.0" encoding="utf-8"?> <relativelayout xmlns:android="http://schemas.android.com/apk/res/android"     android:layout_width="match_parent"     android:layout_height="wrap_content"     android:layout_weight="1"     android:background="@android:color/transparent"     android:padding="5dp" >      <textview         android:id="@+id/txtv_player_input_position_title"         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:layout_alignparentleft="true"         android:layout_alignparenttop="true"         android:layout_marginleft="25dp"         android:layout_margintop="21dp"         android:width="180dp" />      <button         android:id="@+id/btn_edit_title"         style="?android:attr/buttonstylesmall"         android:layout_width="@dimen/btn_edit_player_width"         android:layout_height="wrap_content"         android:layout_alignbaseline="@+id/txtv_player_input_position_title"         android:layout_alignbottom="@+id/txtv_player_input_position_title"         android:layout_alignparentright="true"         android:layout_marginright="14dp"         android:padding="3dp"         android:text="@string/bnt_edit_title" />  </relativelayout> 

custom listviewadapter

import android.app.activity; import android.content.context; import android.view.layoutinflater; import android.view.view; import android.view.viewgroup; import android.widget.baseadapter; import android.widget.button; import android.widget.listview; import android.widget.textview;  public class customlistviewadapter extends baseadapter {        layoutinflater inflater;     list<string> playerlist;      public customlistviewadapter(activity context, list<string> playerlist) {           super();          this.playerlist = playerlist;         this.inflater =     (layoutinflater)context.getsystemservice(context.layout_inflater_service);     }      @override       public int getcount() {           // todo auto-generated method stub           return playerlist.size();       }        @override       public object getitem(int position) {           // todo auto-generated method stub           return null;       }        @override       public long getitemid(int position) {           // todo auto-generated method stub           return 0;       }      static class viewholder {       public textview text;       public button edit;     }     @override       public view getview(final int position, view convertview, viewgroup parent) {           // todo auto-generated method stub           string player = playerlist.get(position);         view vi=convertview;          if(convertview==null)             vi = inflater.inflate(r.layout.new_player_view, null);             viewholder holder = new viewholder(); //        assign components new_player_view //        textview playerinfo = (textview)vi.findviewbyid(r.id.txtv_player_input_position_title);            holder.text = (textview)vi.findviewbyid(r.id.txtv_player_input_position_title);         holder.edit = (button)vi.findviewbyid(r.id.btn_edit_title); //        button editbutton = (button) vi.findviewbyid(r.id.btn_edit_title);         holder.edit.setonclicklistener(mainactivity.editplayerbuttonlistener);         holder.text.settext(player);         //playerinfo.settext("this test");         vi.settag(holder);          return vi;       } 

first of all, using weight property in xml.. should use wisely, don't know why relativelayout has weight 1 anyway, think issue have might 1 of following:

  • make sure getcount() returns > 0
  • make sure using method inflate: inflater.inflate(r.layout.new_player_view, parent, false);
  • change row layout follwing:

    <relativelayout xmlns:android="http://schemas.android.com/apk/res/android"     android:layout_width="match_parent"     android:layout_height="wrap_content"     android:background="@android:color/transparent"     android:padding="5dp" >      <textview         android:id="@+id/txtv_player_input_position_title"         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:layout_alignparentleft="true"         android:layout_alignparenttop="true"         android:layout_marginleft="25dp"/>      <button         android:id="@+id/btn_edit_title"         style="?android:attr/buttonstylesmall"         android:layout_width="@dimen/btn_edit_player_width"         android:layout_height="wrap_content"         android:layout_alignparentright="true"         android:layout_marginright="14dp"         android:padding="3dp"         android:text="@string/bnt_edit_title" /> 

and main layout listview to:

<listview         android:id="@+id/list"         android:layout_width="fill_parent"         android:layout_height="fill_parent" /> 

i hope you, otherwise, please post full code of adapter.

edit:

please try @ this example of viewholder pattern implementation, working , should implement yours better.


Comments

Popular posts from this blog

Ansible - ERROR! the field 'hosts' is required but was not set -

customize file_field button ruby on rails -

SoapUI on windows 10 - high DPI/4K scaling issue -