How to hide spinner dropdown android -
i want hide spinner prompt popup on outside click. if prompt popup open , user press home key activity minimize when user again open application prompt popup should disappear.
there way achieve this. thank
edit:-- prompt popup not customized. can't hide them in onpause
or onresume
methods.
well little complicated thought.
i adding step step details here. try follow it. able achieve in api level 10.
and solution assumes supposed close prompt dialog programatically when user clicks on home button or if had move next activity without user interaction
the first step create custom spinner extending spinner class. let's say, have created class called customspinner in package com.bts.sampleapp
my customspinner class looks this,
package com.bts.sampleapp; import android.content.context; import android.util.attributeset; import android.widget.spinner; public class customspinner extends spinner{ context context=null; public customspinner(context context) { super(context); this.context=context; } public customspinner(context context, attributeset attrs, int defstyle) { super(context, attrs, defstyle); } public customspinner(context context, attributeset attrs) { super(context, attrs); } @override public void ondetachedfromwindow() { super.ondetachedfromwindow(); } }
now in xml file, replace spinner element custom spinner,
<com.bts.sampleapp.customspinner android:id="@+id/spin" android:layout_width="wrap_content" android:layout_height="wrap_content" />
the next step initialize , set adapter spinner in activity class,
@override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); customspinner spin=null; spin=(customspinner)findviewbyid(r.id.spin); spin.setadapter(spinneradapter); //you can set adapter here. }
the final step close dialog when user clicks on homebutton or when activity moves background. this, override onpause() this,
@override protected void onpause() { log.i("life cycle", "onpause"); spin.ondetachedfromwindow(); super.onpause(); }
now within onpause() call method spin.ondetachedfromwindow();
job of closing prompt dialog you.
also calling spin.ondetachedfromwindow();
anywhere within acitivity should close spinner prompt dialog if open.
Comments
Post a Comment