Tuesday, September 10, 2013

[android help] How to Hide and Show List View


How to Hide and Show List View


android - How to Hide and Show List View - Stack Overflow







Tell me more ×

Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.
















I have a listview. Now i need to hide/ display the listview. Listview is at left corner of my screen and now what i want is when i touch the left corner of my layout my listview should hide and when i touch again it should display, which is exactly similar like hiding seek bar in media player at the time of playing video.I searched but i couldn't find the answer. I can show/hide it in layout but i want listview to show and hide exactly when i touches the left corner of the screen. I tried with on touch listener also, but cannot achieve exactly what i want.As am a newbie, help me in achieving this. Thanks in advance


























you can use this way:



yourview.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View view, MotionEvent motionEvent) {
if(motionEvent.getAction() == MotionEvent.ACTION_DOWN){
if(gone == false){
listview.setVisibility(View.GONE);
gone = true;
}else{
listview.setVisibility(View.VISIBLE);
gone = false;

}


}
return true;
}
});


gone is a boolean























easy way to achieve is


1) put a button on your corner where you want to(make button transparent if you dont want to make it visible).


2) set click listener on that button.


eg.



Button corner;
corner.setOnClickListener(new OnClickListener() {

@Override
public void onClick(View v) {
if(lstview.getVisibility()==View.VISIBLE){
lstview.setVisibility(View.GONE);
}else{
lstview.setVisibility(View.VISIBLE);
}
}
});





















object.setVisibility(View.INVISIBLE) or show mateobject.setVisibility(View.VISIBLE)






















i think the esyest solution (not the most elegant) for you is to put a trasparent view in the left corner of your layout (above the other) and set a click listener on it.


the xml:



xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" >

android:id="@+id/invisible_view"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_width="50dp"
android:layout_height="match_parent"
/>

android:id="@+id/listView"
android:layout_width="match_parent"
android:layout_height="match_parent" >





the OnClickListener:



OnClickListener onClickHide = new OnClickListener(){

@Override
public void onClick(View v) {
if(v.isShown()) {
v.setVisibility(View.GONE);
} else {
v.setVisibility(View.VISIBLE);
}
}
};






















default






Read more

stackoverflow.comm



No comments:

Post a Comment

Google Voice on T-Mobile? [General]

Google Voice on T-Mobile? So I recently switched from a GNex on Verizon to a Moto X DE on T-Mobile. I had always used Google Voice for my v...