classcastexpetion when using android:layout_toStartOf -


i have listview until today have positioned 2 views: 1 imageview left of parent, , use textview positioned right of imageview. in xml use following code that:

android:layout_torightof="@+id/single" , single imageview.

... no problem whatsoever :-)

but today came new idea - want imageview in listview. positioned new view right side of parent (listview).

android:layout_alignparentright="true"

now small problem arised when did this: in cases have long sentence in textview overlappes new imageview. according android documentation found code:

android:layout_tostartof="@+id/volume" , volume id new imageview.

i thought work. end of means positions end edge of view start of given anchor view id. [reference]

so thought everthing work when compiled , started test app app crashes when listview clicked. crash due classcastexception. imageview cannot cast textview

so question why classcastexception? thing postion end edge of textview start of imageview. why classcastexception when use tostartof? not exception when position textview right of other imageview , using xml-code android:layout_torightof="@+id/single"

in summary: goal have 3 views in listview: 2 imageview - 1 left , 1 right. , in between of these 2 imageviews want place textview.

i exception in getchildview-method.

<!-- layout för undermenyerna -->  <relativelayout 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" android:paddingbottom="5dp" android:paddingleft="0px" android:paddingright="@dimen/activity_horizontal_margin" android:paddingtop="0px" android:background="#ffffff" tools:context=".phraseactivity" >   <!-- view för ena ena könet, man eller kvinna -->    <textview     android:id="@+id/label_single"     android:layout_width="wrap_content"     android:layout_height="wrap_content"     android:layout_centerinparent="true"     android:layout_torightof="@+id/single"     android:layout_tostartof="@+id/volume"     android:la      />      <!-- texview för båda könen, man och kvinna -->   <textview     android:id="@+id/label_couple"     android:layout_width="wrap_content"     android:layout_height="wrap_content"     android:layout_margintop="20dp"     android:layout_torightof="@+id/couple"      />     <!-- texview för info -->   <textview     android:id="@+id/extra_info"     android:layout_width="wrap_content"     android:layout_height="wrap_content"     android:layout_below="@+id/couple"     android:layout_margintop="10sp"      android:background="@drawable/back_extrainfo"     android:padding="5sp"     android:visibility="gone"     android:textcolor="#8c8c8c"     />    <!-- text länk till bild, tex karta som visar vart staden är thailand -->   <textview     android:id="@+id/imagelink"     android:layout_width="wrap_content"     android:layout_height="wrap_content"     android:visibility="gone"     android:focusableintouchmode="true"     android:text="click view on map"     android:textcolor="#3241d3"     android:layout_centerhorizontal="true"     android:layout_below="@+id/couple"       />    <!-- text länk till bild, samma syfte som texviewen ovan -->   <textview     android:id="@+id/imagelink2"     android:layout_width="wrap_content"     android:layout_height="wrap_content"     android:visibility="gone"     android:text="click view image"     android:focusableintouchmode="true"     android:textcolor="#3241d3"     android:layout_centerhorizontal="true"     android:layout_below="@+id/extra_info"       />   <!-- view för en bild av ena könet, man eller kvinna -->   <imageview     android:id="@+id/single"     android:layout_width="68sp"     android:layout_height="68sp"      />   <!-- view för en bild av båda könen, man och kvinna --> <imageview     android:id="@+id/couple"    android:layout_width="100sp"    android:layout_height="68sp"    />  <imageview     android:id="@+id/volume"     android:layout_width="100sp"     android:layout_height="79sp"     android:layout_alignparentright="true" />  </relativelayout>        public view getchildview(int groupposition, int childposition, boolean islastchild, view convertview, viewgroup parent) {       final viewholder holder;        if (convertview == null) {           layoutinflater inflater = (layoutinflater) context.getsystemservice(context.layout_inflater_service);           convertview = inflater.inflate(r.layout.activity_subphrase, parent, false);           holder = new viewholder();           holder.text = (textview) convertview.findviewbyid(r.id.label_single);           holder.text2 = (textview) convertview.findviewbyid(r.id.label_couple);           holder.imageview = (imageview) convertview.findviewbyid(r.id.single);           holder.imageview2 = (imageview) convertview.findviewbyid(r.id.couple);           holder.volumecontrol = (imageview) convertview.findviewbyid(r.id.volume);           convertview.settag(holder);        } else {             holder = (viewholder) convertview.gettag();       }       final int nchildren = getchildrencount(groupposition);         final view v = convertview;       switch (nchildren) {         case 1:             holder.imageview.setbackgroundresource(0);             holder.imageview2.bringtofront();             holder.imageview2.setvisibility(imageview.visible);             holder.text.settext(null);             holder.text2.settext(contents[groupposition][childposition]);             holder.imageview2.setbackgroundresource(r.drawable.man_woman_3);              //extra(groupposition, category, holder.text, convertview, parent);             showthaiimages(groupposition, holder.text, convertview, parent);             // väntar till layout är avklarad - efter detta bearbetas animering.               vto = convertview.getviewtreeobserver();             vto.addongloballayoutlistener(new ongloballayoutlistener() {              public void ongloballayout() {                 v.getviewtreeobserver().removeongloballayoutlistener(this);  //vet inte om denna metod är nödvändig                 holder.imageview2.bringtofront();                 holder.imageview2.setbackgroundresource(r.drawable.animation3);                 frameanimation = (animationdrawable) holder.imageview2.getbackground();                 frameanimation.start();             }});              break;          case 2:               try {                 system.out.println("viewtreeobserver alive = : " + vto.isalive());             } catch (exception e) {                 e.printstacktrace();             }              //v.getviewtreeobserver().removeongloballayoutlistener(new viewtreeobserver.ongloballayoutlistener());   //vet inte om denna metod är nödvändig             holder.imageview2.setvisibility(view.gone);             holder.imageview2.setbackgroundresource(0);             holder.imageview.bringtofront();             holder.text2.settext(null);             //holder.imageview.invalidate();             holder.text.settext(contents[groupposition][childposition]);             switch (childposition) { // switch-villkor för man eller kvinna.                  case 0: // man.                     holder.imageview.setbackgroundresource(r.drawable.man_3);                     break;                 case 1: // kvinna.                     holder.imageview.setbackgroundresource(r.drawable.woman_3);                     break;             }             break;       }        holder.volumecontrol.setbackgroundresource(r.drawable.speaker);       notifydatasetchanged();       return convertview;   } 

delete gen folder , clean project , try again.this error comes wwhen change position of views.

try once.


Comments

Popular posts from this blog

Unable to remove the www from url on https using .htaccess -