android - Adding a Vertical Line to the SimpleCursorAdapter ListView -


i have listview, , list contain layout view component added relativelayout :

<relativelayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" >  <textview      android:id="@+id/no"     android:layout_width="40dp"      android:layout_height="40dp"     android:layout_margintop="5dp"     android:layout_marginbottom="5dp"     android:layout_marginleft="10dp"     android:layout_marginright="5dp"     android:gravity="center"     />  <view     android:id="@+id/line"     android:layout_width="0.3dip"     android:layout_height="wrap_content"     android:layout_torightof="@+id/no"     android:background="#ffdddddd" />  <textview      android:id="@+id/name"     android:textcolor="#150517"     android:layout_width="wrap_content"      android:layout_height="wrap_content"     android:layout_torightof="@+id/line"     android:layout_margintop="15dp"     android:layout_marginleft="20dp"     android:layout_marginright="10dp"     android:layout_gravity="right"     android:layout_alignparentright="true"     android:gravity="right"     android:textsize="38sp"  /> </relativelayout> 

code of mycursoradapter.java :

  public class mycursoradapter extends simplecursoradapter{    public mycursoradapter(context context, int layout, cursor c, string[] from, int[] to, int flags) {       super(context, layout, c, from, to, flags);   }    @override    public view getview(int position, view convertview, viewgroup parent) {       view view = convertview;       if(position % 2 == 0){           view.setbackgroundcolor(color.rgb(243, 234, 214));       }else{           view.setbackgroundcolor(color.rgb(253, 247, 230));       }       ((textview)view.findviewbyid(r.id.name)).settypeface(typeface.createfromasset(view.getcontext().getassets(), "fonts/nytype.ttf"));       return view;     }  }   

when start run app. there errors messages :

e/androidruntime(19583): fatal exception: main

e/androidruntime(19583): java.lang.illegalstateexception: android.view.view not view can bounds simplecursoradapter

e/androidruntime(19583): @ android.support.v4.widget.simplecursoradapter.bindview(simplecursoradapter.java:145)

how fix problem?

its because doing this

view view = super.getview(position, convertview, parent); 

you dont want that, need set view convertview

view view = convertview; 

check if view null, if inflate view want here

if(view == null){     view = getlayoutinflater().inflate(r.layout.name,null); }  

here example of how it

@override public view getview(int position, view convertview, viewgroup parent){     view v = convertview;     if(v == null){         convertview = view.inflate(context,r.layout.sin_preplan_row,null);     }      bindview(position, convertview);     return convertview; }  private void bindview(int position, view view){     map<string,object> data = list.get(position);      textview name = (textview)view.findviewbyid(r.id.name_text);     textview address = (textview)view.findviewbyid(r.id.address_text);     textview notes = (textview)view.findviewbyid(r.id.notes_text);     textview distance = (textview)view.findviewbyid(r.id.distance_text);      name.settext((string)data.get("name"));     address.settext((string)data.get("address"));     notes.settext((string)data.get(notes));     distance.settext(string.valueof((float)data.get("distance")));  } 

edit:

change xml this

<relativelayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" >  <textview  android:id="@+id/no" android:layout_width="40dp"  android:layout_height="40dp" android:layout_margintop="5dp" android:layout_marginbottom="5dp" android:layout_marginleft="10dp" android:layout_marginright="5dp" android:gravity="center" />  <framelayout android:id="@+id/line" android:layout_width="0.3dip" android:layout_height="wrap_content" android:layout_torightof="@+id/no" android:background="#ffdddddd" />  <textview  android:id="@+id/name" android:textcolor="#150517" android:layout_width="wrap_content"  android:layout_height="wrap_content" android:layout_torightof="@+id/line" android:layout_margintop="15dp" android:layout_marginleft="20dp" android:layout_marginright="10dp" android:layout_gravity="right" android:layout_alignparentright="true" android:gravity="right" android:textsize="38sp"  /> </relativelayout> 

Comments

Popular posts from this blog

blackberry 10 - how to add multiple markers on the google map just by url? -

php - guestbook returning database data to flash -

delphi - Dynamic file type icon -