android studio - I want to show enable a button on first click and when other button is clicked, then the previously clicked one should be inactive -


i had set images in drawable , tried set them using onclicklisteners , uing view.visible , view.gone once button clicked becomes active forever whereas want clicked button disabled or inactive when new 1 clicked. please me out anyone? xml code:

<linearlayout     android:layout_width="wrap_content" android:layout_height="wrap_content"     android:layout_alignbottom="@+id/toolbartitle"     android:layout_toleftof="@+id/toolbartitle"     android:layout_tostartof="@+id/toolbartitle"     android:id="@+id/linearlayout3"     android:orientation="horizontal"></linearlayout>  <horizontalscrollview     android:layout_width="match_parent" android:layout_height="wrap_content"     android:id="@+id/horizontalscrollview"     android:fillviewport="false"     android:background="#ffffff"     android:layout_alignparenttop="true"     android:layout_alignparentleft="true"     android:layout_alignparentstart="true"     android:scrollbars="none"     android:scrollbaralwaysdrawhorizontaltrack="true"     android:contextclickable="false"     android:focusable="false"     android:layout_margintop="80dp"> <relativelayout     android:layout_width="match_parent" android:layout_height="wrap_content"     android:background="#ffffff"     android:layout_aligntop="@+id/horizontalscrollview"     android:layout_alignparentleft="true"     android:layout_alignparentstart="true">      <relativelayout         android:layout_width="match_parent" android:layout_height="wrap_content"         android:id="@+id/miniscrollrelative"         android:layout_alignparenttop="true"         android:layout_alignparentleft="true"         android:layout_alignparentstart="true">          <textview             android:layout_width="wrap_content" android:layout_height="wrap_content"             android:text="@string/home"             android:id="@+id/textviewab"             android:layout_alignparentleft="true"             android:layout_alignparentstart="true"             android:layout_marginleft="20dp"             android:layout_margintop="50dp"             android:textsize="8dp"/>          <textview             android:layout_width="wrap_content" android:layout_height="wrap_content"             android:text="@string/player"             android:id="@+id/textviewba"             android:layout_alignparenttop="true"             android:layout_alignparentleft="true"             android:layout_alignparentstart="true"             android:layout_marginleft="70dp"             android:layout_margintop="50dp"             android:textsize="8dp" />         <textview             android:layout_width="wrap_content" android:layout_height="wrap_content"             android:text="@string/your_play.."             android:id="@+id/textviewca"             android:layout_alignparenttop="true"             android:layout_alignparentleft="true"             android:layout_alignparentstart="true"             android:layout_marginleft="130dp"             android:layout_margintop="50dp"             android:textsize="8dp" />         <textview             android:layout_width="wrap_content" android:layout_height="wrap_content"             android:text="@string/downloads"             android:id="@+id/textviewda"             android:layout_alignparenttop="true"             android:layout_alignparentleft="true"             android:layout_alignparentstart="true"             android:layout_marginleft="200dp"             android:layout_margintop="50dp"             android:textsize="8dp" />         <textview             android:layout_width="wrap_content" android:layout_height="wrap_content"             android:textappearance="?android:attr/textappearancesmall"             android:text="@string/streaming"             android:id="@+id/textviewea"             android:layout_alignparenttop="true"             android:layout_alignparentleft="true"             android:layout_alignparentstart="true"             android:layout_marginleft="270dp"             android:layout_margintop="50dp"             android:textsize="8dp" />         <imagebutton             android:layout_width="wrap_content" android:layout_height="wrap_content"             android:id="@+id/imagebuttonhomea"             android:src="@drawable/homenew"             android:background="#ffffff"             android:paddingleft="10dp"             android:paddingbottom="10dp"             android:paddingright="10dp"             android:paddingtop="8dp"             android:layout_alignbottom="@+id/imagebuttonda"             android:layout_torightof="@+id/imagebuttonaab"             android:layout_toendof="@+id/imagebuttonaab" />          <imagebutton             android:layout_width="wrap_content" android:layout_height="wrap_content"             android:id="@+id/imagebuttonaa"             android:src="@drawable/player"             android:layout_marginleft="60dp"             android:background="#ffffff"             android:layout_margintop="10dp"             android:paddingleft="10dp"             android:paddingbottom="10dp"             android:paddingright="10dp"             android:paddingtop="8dp"/>         <imagebutton             android:layout_width="wrap_content" android:layout_height="wrap_content"             android:id="@+id/imagebuttonaab"             android:src="@drawable/player_active"             android:layout_marginleft="60dp"             android:background="#ffffff"             android:layout_margintop="10dp"             android:paddingleft="10dp"             android:paddingbottom="10dp"             android:paddingright="10dp"             android:paddingtop="8dp"             android:visibility="gone"/>          <imagebutton             android:layout_width="wrap_content" android:layout_height="wrap_content"             android:id="@+id/imagebuttonba"             android:src="@drawable/mydownload"             android:layout_marginleft="195dp"             android:background="#ffffff"             android:paddingleft="10dp"             android:paddingbottom="10dp"             android:paddingright="10dp"             android:paddingtop="8dp"             android:layout_margintop="10dp"/>         <imagebutton             android:layout_width="wrap_content" android:layout_height="wrap_content"             android:id="@+id/imagebuttonbab"             android:src="@drawable/download_active"             android:layout_marginleft="195dp"             android:background="#ffffff"             android:paddingleft="10dp"             android:paddingbottom="10dp"             android:paddingright="10dp"             android:paddingtop="8dp"             android:layout_margintop="10dp"             android:visibility="gone"/>         <imagebutton             android:layout_width="wrap_content" android:layout_height="wrap_content"             android:id="@+id/imagebuttonca"             android:src="@drawable/playlist"             android:layout_marginleft="130dp"             android:background="#ffffff"             android:paddingleft="10dp"             android:paddingbottom="10dp"             android:paddingright="10dp"             android:paddingtop="8dp"             android:layout_margintop="10dp"             />         <imagebutton             android:layout_width="wrap_content" android:layout_height="wrap_content"             android:id="@+id/imagebuttoncab"             android:src="@drawable/playlist_active"             android:layout_marginleft="130dp"             android:background="#ffffff"             android:paddingleft="10dp"             android:paddingbottom="10dp"             android:paddingright="10dp"             android:paddingtop="8dp"             android:layout_margintop="10dp"             android:visibility="gone"/>         <imagebutton             android:layout_width="wrap_content" android:layout_height="wrap_content"             android:id="@+id/imagebuttonda"             android:src="@drawable/streaming"             android:layout_marginleft="265dp"             android:background="#ffffff"             android:paddingleft="10dp"             android:paddingbottom="10dp"             android:paddingright="10dp"             android:paddingtop="8dp"             android:layout_margintop="10dp"/>         <imagebutton             android:layout_width="wrap_content" android:layout_height="wrap_content"             android:id="@+id/imagebuttondab"             android:src="@drawable/streaming_active"             android:layout_marginleft="265dp"             android:background="#ffffff"             android:paddingleft="10dp"             android:paddingbottom="10dp"             android:paddingright="10dp"             android:paddingtop="8dp"             android:layout_margintop="10dp"             android:visibility="gone"/>       </relativelayout>     <relativelayout         android:layout_width="match_parent" android:layout_height="wrap_content"         android:layout_torightof="@+id/miniscrollrelative"         android:layout_marginleft="30dp">         <textview             android:layout_width="wrap_content" android:layout_height="wrap_content"             android:textappearance="?android:attr/textappearancesmall"             android:text="@string/send_wishes"             android:id="@+id/textviewfa"             android:textsize="8dp"             android:layout_marginleft="8dp"             android:layout_margintop="50dp"             />         <textview             android:layout_width="wrap_content" android:layout_height="wrap_content"             android:textappearance="?android:attr/textappearancesmall"             android:text="@string/hit_parade"             android:id="@+id/textviewga"             android:textsize="8dp"             android:layout_marginleft="78dp"             android:layout_margintop="50dp"             />         <textview             android:layout_width="wrap_content" android:layout_height="wrap_content"             android:textappearance="?android:attr/textappearancesmall"             android:text="@string/uzbek_instr"             android:id="@+id/textviewha"             android:textsize="8dp"             android:layout_marginleft="145dp"             android:layout_margintop="50dp"             />         <textview             android:layout_width="wrap_content" android:layout_height="wrap_content"             android:textappearance="?android:attr/textappearancesmall"             android:text="@string/your_news"             android:id="@+id/textviewia"             android:textsize="8dp"             android:layout_marginleft="220dp"             android:layout_margintop="50dp"             />         <textview             android:layout_width="wrap_content" android:layout_height="wrap_content"             android:textappearance="?android:attr/textappearancesmall"             android:text="@string/extras"             android:id="@+id/textviewja"             android:textsize="8dp"             android:layout_marginleft="300dp"             android:layout_margintop="50dp"             android:layout_marginright="5dp"/>         <imagebutton             android:layout_width="wrap_content" android:layout_height="wrap_content"             android:id="@+id/imagebuttonea"             android:src="@drawable/wishes"             android:paddingleft="10dp"             android:paddingbottom="10dp"             android:paddingright="10dp"             android:paddingtop="8dp"             android:background="#ffffff"             android:layout_aligntop="@+id/imagebuttonfa"             android:layout_alignparentleft="true"             android:layout_alignparentstart="true" />         <imagebutton             android:layout_width="wrap_content" android:layout_height="wrap_content"             android:id="@+id/imagebuttoneab"             android:src="@drawable/hitparadea"             android:layout_marginleft="10dp"             android:layout_margintop="10dp"             android:paddingleft="10dp"             android:paddingbottom="10dp"             android:paddingright="10dp"             android:paddingtop="8dp"             android:background="#ffffff"             android:visibility="gone"/>         <imagebutton             android:layout_width="wrap_content" android:layout_height="wrap_content"             android:id="@+id/imagebuttonfa"             android:src="@drawable/hitparade"             android:layout_marginleft="80dp"             android:layout_margintop="10dp"             android:background="#ffffff"             android:paddingleft="10dp"             android:paddingbottom="10dp"             android:paddingright="10dp"             android:paddingtop="8dp"/>         <imagebutton             android:layout_width="wrap_content" android:layout_height="wrap_content"             android:id="@+id/imagebuttonfab"             android:src="@drawable/hitparade1"             android:layout_marginleft="80dp"             android:layout_margintop="10dp"             android:background="#ffffff"             android:paddingleft="10dp"             android:paddingbottom="10dp"             android:paddingright="10dp"             android:paddingtop="8dp"             android:visibility="gone"/>         <imagebutton             android:layout_width="wrap_content" android:layout_height="wrap_content"             android:id="@+id/imagebuttonga"             android:src="@drawable/instrument"             android:layout_marginleft="150dp"             android:layout_margintop="10dp"             android:paddingleft="10dp"             android:paddingbottom="10dp"             android:paddingright="10dp"             android:paddingtop="8dp"             android:background="#ffffff"/>         <imagebutton             android:layout_width="wrap_content" android:layout_height="wrap_content"             android:id="@+id/imagebuttongab"             android:src="@drawable/instrument_active"             android:layout_marginleft="150dp"             android:layout_margintop="10dp"             android:paddingleft="10dp"             android:paddingbottom="10dp"             android:paddingright="10dp"             android:paddingtop="8dp"             android:background="#ffffff"             android:visibility="gone"/>         <imagebutton             android:layout_width="wrap_content" android:layout_height="wrap_content"             android:id="@+id/imagebuttonha"             android:src="@drawable/news"             android:layout_marginleft="220dp"             android:layout_margintop="10dp"             android:paddingleft="10dp"             android:paddingbottom="10dp"             android:paddingright="10dp"             android:paddingtop="8dp"             android:background="#ffffff"/>         <imagebutton             android:layout_width="wrap_content" android:layout_height="wrap_content"             android:id="@+id/imagebuttonhab"             android:src="@drawable/news_active"             android:layout_marginleft="220dp"             android:layout_margintop="10dp"             android:paddingleft="10dp"             android:paddingbottom="10dp"             android:paddingright="10dp"             android:paddingtop="8dp"             android:background="#ffffff"             android:visibility="gone"/>         <imagebutton             android:layout_width="wrap_content" android:layout_height="wrap_content"             android:id="@+id/imagebuttonia"             android:src="@drawable/extras"             android:layout_marginleft="290dp"             android:layout_margintop="10dp"             android:background="#ffffff"             android:paddingleft="10dp"             android:paddingbottom="10dp"             android:paddingright="10dp"             android:paddingtop="8dp"             android:layout_marginright="5dp"/>         <imagebutton             android:layout_width="wrap_content" android:layout_height="wrap_content"             android:id="@+id/imagebuttoniab"             android:src="@drawable/extras_active"             android:layout_marginleft="290dp"             android:layout_margintop="10dp"             android:background="#ffffff"             android:paddingleft="10dp"             android:paddingbottom="10dp"             android:paddingright="10dp"             android:paddingtop="8dp"             android:layout_marginright="5dp"             android:visibility="gone"/>      </relativelayout> </relativelayout> </horizontalscrollview> <imagebutton     android:layout_height="wrap_content"     android:layout_width="wrap_content"     android:background="@drawable/right"     android:layout_alignparentright="true"     android:layout_alignparentend="true"     android:layout_alignbottom="@+id/horizontalscrollview"     android:layout_aligntop="@+id/toolbar"     android:id="@+id/right" /> <imagebutton     android:id="@+id/left"     android:layout_height="wrap_content"     android:layout_width="wrap_content"     android:background="@drawable/left"     android:layout_alignparentleft="true"     android:layout_alignparentstart="true"     android:layout_alignbottom="@+id/horizontalscrollview"     android:layout_aligntop="@+id/toolbar" /> <framelayout     android:layout_width="match_parent" android:layout_height="match_parent"     android:name="android.app.listfragment"     android:id="@+id/fragment"     android:background="#ffffff"     android:layout_below="@+id/horizontalscrollview"     android:layout_alignright="@+id/toolbar"     android:layout_alignend="@+id/toolbar">      <framelayout         android:background="#f2434242"         android:layout_width="match_parent"         android:layout_height="202dp"         android:layout_gravity="left|bottom">          <relativelayout             android:background="#f2696868"             android:layout_width="match_parent"             android:layout_height="131dp"             android:id="@+id/relativelayoutad"             android:layout_alignparentbottom="true"             android:layout_alignparentleft="true"             android:layout_alignparentstart="true"             android:layout_gravity="center_horizontal|bottom">              <textview                 android:layout_width="wrap_content"                 android:layout_height="wrap_content"                 android:text="ad"                 android:id="@+id/textview7"                 android:layout_centervertical="true"                 android:layout_centerhorizontal="true" />         </relativelayout>          <relativelayout             android:id="@+id/relativelayout1"             android:layout_width="match_parent"             android:layout_height="100dp"             android:layout_gravity="center_horizontal|top">              <imageview                 android:layout_width="49dp"                 android:layout_height="49dp"                 android:background="@drawable/playerbar"                 android:layout_alignparentleft="true"                 android:layout_alignparentstart="true"                 android:id="@+id/imageview3"                 android:layout_alignparenttop="true"                 android:layout_above="@+id/seekbar2" />              <imagebutton                 android:background="@drawable/minipause"                 android:layout_width="35dp"                 android:layout_height="35dp"                 android:id="@+id/button2"                 android:layout_gravity="center_horizontal|top"                 android:layout_marginright="27dp"                 android:layout_marginend="27dp"                 android:layout_alignparenttop="true"                 android:layout_toleftof="@+id/button4"                 android:layout_tostartof="@+id/button4" />              <imagebutton                 android:background="@drawable/minisound"                 android:layout_width="35dp"                 android:layout_height="35dp"                 android:id="@+id/button4"                 android:layout_gravity="center_horizontal|top"                 android:layout_aligntop="@+id/button2"                 android:layout_alignparentright="true"                 android:layout_alignparentend="true" />              <seekbar                 android:layout_width="match_parent"                 android:layout_height="2dp"                 android:id="@+id/seekbar2"                 android:layout_weight="0.87"                 android:progress="100"                 android:progressdrawable="@drawable/seekbar3"                 android:max="200"                 android:thumb="@null"                 android:maxheight="3dp"                 android:paddingleft="10dp"                 android:paddingright="10dp"                 android:layout_below="@+id/button2"                 android:layout_alignparentleft="true"                 android:layout_alignparentstart="true"                 android:layout_margintop="30dp" />              <textview                 android:layout_width="wrap_content"                 android:layout_height="wrap_content"                 android:text="radio"                 android:textcolor="#ffffff"                 android:id="@+id/textview5"                 android:layout_aligntop="@+id/imageview3"                 android:layout_torightof="@+id/imageview3"                 android:layout_toendof="@+id/imageview3" />              <textview                 android:layout_width="wrap_content"                 android:layout_height="wrap_content"                 android:text="uz"                 android:textcolor="#ffffff"                 android:id="@+id/textview6"                 android:layout_alignleft="@+id/textview5"                 android:layout_alignstart="@+id/textview5"                 android:layout_alignright="@+id/textview5"                 android:layout_alignend="@+id/textview5"                 android:layout_below="@+id/textview5" />          </relativelayout>      </framelayout>  </framelayout>  <textview     android:layout_width="match_parent" android:layout_height="50dp"     android:text="player"      android:textsize="22sp"     android:gravity = "center"     android:id="@+id/toolbartitle"     android:layout_above="@+id/toolbar"     android:layout_alignleft="@+id/toolbar"     android:layout_alignstart="@+id/toolbar" />  </relativelayout> 

and here java code:

public class fragmentforscrollbar extends fragment { @nullable @override public view oncreateview(layoutinflater inflater, viewgroup container, bundle savedinstancestate) {     view view =  inflater.inflate(r.layout.fragmentforscrollbar,null);      myplayer playerfragment = new myplayer();     fragmenttransaction = getchildfragmentmanager().begintransaction();     fragmenttransaction.replace(r.id.fragment, playerfragment, null);     fragmenttransaction.commit();  hsv = (horizontalscrollview) view.findviewbyid(r.id.horizontalscrollview);     t = (textview)view.findviewbyid(r.id.toolbartitle);     home =(imagebutton)view.findviewbyid(r.id.imagebuttonhomea);     player =(imagebutton)view.findviewbyid(r.id.imagebuttonaa);     playlist =(imagebutton)view.findviewbyid(r.id.imagebuttonca);     download =(imagebutton)view.findviewbyid(r.id.imagebuttonba);     stream =(imagebutton)view.findviewbyid(r.id.imagebuttonda);     wish =(imagebutton)view.findviewbyid(r.id.imagebuttonea);     hit =(imagebutton)view.findviewbyid(r.id.imagebuttonfa);     instrument =(imagebutton)view.findviewbyid(r.id.imagebuttonga);     news1 =(imagebutton)view.findviewbyid(r.id.imagebuttonha);     extras1 =(imagebutton)view.findviewbyid(r.id.imagebuttonia);      homea =(imagebutton)view.findviewbyid(r.id.imagebuttonhomea);     playera =(imagebutton)view.findviewbyid(r.id.imagebuttonaab);     playlista =(imagebutton)view.findviewbyid(r.id.imagebuttoncab);     downloada =(imagebutton)view.findviewbyid(r.id.imagebuttonbab);     streama =(imagebutton)view.findviewbyid(r.id.imagebuttondab);     wisha =(imagebutton)view.findviewbyid(r.id.imagebuttoneab);     hita =(imagebutton)view.findviewbyid(r.id.imagebuttonfab);     instrumenta=(imagebutton)view.findviewbyid(r.id.imagebuttongab);     newsa =(imagebutton)view.findviewbyid(r.id.imagebuttonhab);     extrasa =(imagebutton)view.findviewbyid(r.id.imagebuttoniab);      miniplay= (imagebutton) view.findviewbyid(r.id.button2); minisound= (imagebutton) view.findviewbyid(r.id.button4);     final imagebutton bp = (imagebutton) view.findviewbyid(r.id.left);     final imagebutton bn = (imagebutton) view.findviewbyid(r.id.right);      miniplay.setonclicklistener(new view.onclicklistener(){          @override         public void onclick(view v) {             if (v.getid() == r.id.minipause) {                  mediaplayer mediaplayer= new mediaplayer();                 try {                     mediaplayer.setdatasource(url);                     mediaplayer.prepare();                  } catch (exception e) {                     e.printstacktrace();                 }                  if (!mediaplayer.isplaying()) {                     mediaplayer.start();                     miniplay.setimageresource(r.drawable.minipause);                 } else {                     mediaplayer.pause();                     miniplay.setimageresource(r.drawable.miniplay);}         }});     bp.setonclicklistener(new view.onclicklistener() {         @override         public void onclick(view v) {             bp.setvisibility(view.visible);            // bp1.setvisibility(view.gone);             hsv.scrollto(0, -500);             //if it's first/last element can bprevoius.setenabled(false)           }     });       bn.setonclicklistener(new view.onclicklistener() {         @override         public void onclick(view v) {             bn.setvisibility(view.visible);            // bn1.setvisibility(view.gone);             hsv.scrollto(500, 0); //                bn.setimageresource(r.drawable.right);          }     });     home.setonclicklistener(new view.onclicklistener() {         @override         public void onclick(view v) {             t.settext("home");             fragment home = new home();             fragmenttransaction = getchildfragmentmanager().begintransaction();             fragmenttransaction.replace(r.id.fragment, home);             fragmenttransaction.addtobackstack(null);             // fragmenttransaction.popbackstack();             fragmenttransaction.commit();             //  t.settext("player");       }});     player.setonclicklistener(new view.onclicklistener() {         @override         public void onclick(view v) { //                player.setvisibility(view.visible); //                playera.setvisibility(view.gone);             player.setenabled(true);             t.settext("player");             fragment myplayer = new myplayer();             fragmenttransaction = getchildfragmentmanager().begintransaction();             fragmenttransaction.replace(r.id.fragment, myplayer);             fragmenttransaction.addtobackstack(null);            // fragmenttransaction.popbackstack();             fragmenttransaction.commit(); //                player.setimageresource(r.drawable.player_active); //                playera.setimageresource(r.drawable.player);         }     });     }} 


Comments

Popular posts from this blog

python - How to insert QWidgets in the middle of a Layout? -

python - serve multiple gunicorn django instances under nginx ubuntu -

module - Prestashop displayPaymentReturn hook url -