Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

setvisibility(view.visible) not working after setvisibility(view.gone)

I saw some post about this and I understood the problem. But how can go around it? I have ListView with item that can be expanded but once the view is gone it cannot be visible again, unless it has a free space. How to make that space?

private void mySetOnItemListener() {
    l.setOnItemClickListener(new OnItemClickListener() {

    @Override
    public void onItemClick(AdapterView<?> arg0, View view,
            int position, long arg3) {
        Log.d("onItemClick","called");
        LinearLayout ll = (LinearLayout)view.findViewById(R.id.llOpenedField);
        ll.setVisibility(View.VISIBLE);
    }
    });
}

my viewLayout

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical" 
    android:descendantFocusability="blocksDescendants">

    <LinearLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:orientation="horizontal"
        android:weightSum="5" >

        <TextView
            android:id="@+id/tv_name"
            android:layout_width="0px"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:layout_weight="4"
            android:padding="7dp"
            android:text="item"
            android:textColor="@android:color/background_dark"
            android:textSize="25dp" />
    </LinearLayout>

      <LinearLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/llOpenedField"
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:orientation="horizontal"

         >

        <ImageButton
            android:id="@+id/ibInformation"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:src="@drawable/info" />

    </LinearLayout>

</LinearLayout>

the LinearLayout android:id="@+id/llOpenedField" is what im trying to make gone at start .

i put the gone attribute in the getView() inside BaseAdapter .

like image 285
Jesus Dimrix Avatar asked Apr 24 '13 11:04

Jesus Dimrix


2 Answers

If you put the code making an element visible into its onClickListener, it won't be reachable (if it consumes none of the screen-space, you won't be able to click on it). You should put a layout with a minimal height below it, and when your view l becomes gone, the new layout shell become visible, and it should get the visible-making onClickListener. This way, after your View becomes gone, this new layout will be able to bring it back.

like image 200
Analizer Avatar answered Nov 10 '22 02:11

Analizer


please check this answer. This answer work for me.

TranslateAnimation translateAnimation = new TranslateAnimation(0, 50, 0, 0);
          int animationTime = 200;
          translateAnimation.setDuration(animationTime);
          translateAnimation.setFillEnabled(true);
          translateAnimation.setFillAfter(true);
          yourView.startAnimation(translateAnimation);
          yourView.setVisibility(View.VISIBLE);
like image 37
TMD Avatar answered Nov 10 '22 03:11

TMD