android - Problem with a button -
<?xml version="1.0" encoding="utf-8"?> <linearlayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="wrap_content" android:layout_height="wrap_content" > <linearlayout android:orientation="horizontal" android:layout_width="fill_parent" android:layout_height="wrap_content" android:paddingbottom="20px" > <button android:id="@+id/expandbutton" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text=" + " android:focusable="false" android:focusableintouchmode="false" android:clickable="false" /> <textview android:id="@+id/joketextview" android:layout_width="fill_parent" android:layout_height="wrap_content" android:textsize="16px" android:singleline="true" /> </linearlayout> <linearlayout android:orientation="horizontal" android:layout_width="fill_parent" android:layout_height="wrap_content" > <radiogroup android:id="@+id/ratingradiogroup" android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="horizontal"> <radiobutton android:id="@+id/likebutton" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginleft="60px" android:text="like" /> <radiobutton android:id="@+id/dislikebutton" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginleft="60px" android:text="dislike" /> </radiogroup> </linearlayout> </linearlayout>
i have class extends view(linearlayout)
import ... public class jokeview extends linearlayout{ private button m_vwexpandbutton; private radiobutton m_vwlikebutton; private radiobutton m_vwdislikebutton; private radiogroup m_vwlikegroup; private textview m_vwjoketext; private joke m_joke; public static final string expand = " + "; public static final string collapse = " - "; public jokeview(context context, joke joke) { super(context); layoutinflater inflater = (layoutinflater)context.getsystemservice( context.layout_inflater_service); inflater.inflate(r.layout.joke_view, this, true); m_vwexpandbutton=(button)findviewbyid(r.id.expandbutton); m_vwlikebutton=(radiobutton)findviewbyid(r.id.likebutton); m_vwdislikebutton=(radiobutton)findviewbyid(r.id.dislikebutton); m_vwlikegroup=(radiogroup)findviewbyid(r.id.ratingradiogroup); m_vwjoketext=(textview)findviewbyid(r.id.joketextview); setjoke(joke); collapsejokeview(); m_vwexpandbutton.setonclicklistener(new onclicklistener(){ @override public void onclick(view v){ log.e("tah", "onclick"); if(m_vwexpandbutton.gettext().equals(jokeview.expand)){ expandjokeview(); } else if(m_vwexpandbutton.gettext().equals(jokeview.collapse)){ collapsejokeview(); } } }); m_vwlikegroup.setoncheckedchangelistener(new oncheckedchangelistener(){ @override public void oncheckedchanged(radiogroup rg, int i) { if(i==1){ m_joke.setrating(joke.like); } else if(i==2){ m_joke.setrating(joke.dislike); } } }); } public void setjoke(joke joke) { if(joke!=null){ m_joke=joke; m_vwjoketext.settext(joke.getjoke()); switch(joke.getrating()){ case joke.like: m_vwlikebutton.setchecked(true); break; case joke.dislike: m_vwdislikebutton.setchecked(true); break; case joke.unrated: m_vwlikegroup.clearcheck(); break; } } } private void expandjokeview() { m_vwjoketext.setellipsize(null); m_vwjoketext.setsingleline(false); m_vwlikegroup.setvisibility(view.visible); m_vwexpandbutton.settext(jokeview.collapse); this.requestlayout(); } private void collapsejokeview() { m_vwjoketext.setsingleline(true); m_vwjoketext.setellipsize(textutils.truncateat.end); m_vwlikegroup.setvisibility(view.gone); m_vwexpandbutton.settext(jokeview.expand); this.requestlayout(); } }
but onclick happens when click on button
the question bit vague. suspect since haven't provided onclick method button click call, it's defaulting 1 can find. try this:
android:onclick="expandbuttonclicked"
then provide method compiler find.
Comments
Post a Comment