Reputation: 325
I've done an Activity with an image in full screen and below a textview with its description. What I want is to make invisible textview when I click on the image. I have placed a Toast and there goes the code, but is not invisible. What can be the error? thanks
public Object instantiateItem(ViewGroup view, int position) {
View imageLayout = inflater.inflate(R.layout.ampliar_imagen, view, false);
assert imageLayout != null;
imageView = (TouchImageView) imageLayout.findViewById(R.id.imagenFullScreen);
info = (TextView) imageLayout.findViewById(R.id.textoInfoImagen);
final ProgressBar spinner = (ProgressBar) imageLayout.findViewById(R.id.cargandoFoto);
imageView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(ImagePagerActivity.this, "CLICK", Toast.LENGTH_SHORT).show();
info.setVisibility(View.GONE);
}
});
imageLoader.displayImage(images[position], imageView, options, new SimpleImageLoadingListener() {
@Override
public void onLoadingStarted(String imageUri, View view) {
spinner.setVisibility(View.VISIBLE);
}
@Override
public void onLoadingFailed(String imageUri, View view, FailReason failReason) {
Toast.makeText(ImagePagerActivity.this, "Error al cargar la imagen", Toast.LENGTH_SHORT).show();
spinner.setVisibility(View.GONE);
}
@Override
public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) {
spinner.setVisibility(View.GONE);
}
});
view.addView(imageLayout, 0);
return imageLayout;
}
XML
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/negro" >
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent" >
<imagenes.TouchImageView
android:id="@+id/imagenFullScreen"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:adjustViewBounds="true" />
<ProgressBar
android:id="@+id/cargandoFoto"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:visibility="gone" />
</FrameLayout>
<TextView
android:id="@+id/textoInfoImagen"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="@color/grisTransparente"
android:gravity="center_horizontal"
android:paddingBottom="3dp"
android:paddingTop="3dp"
android:text="AAAA"
android:textColor="@color/blanco"
android:textSize="13sp" />
</RelativeLayout>
Upvotes: 1
Views: 1365
Reputation: 1536
I will suggest you to set your imageLayout as tag of imageView and in onClick of image view get your textview from tag layout and then set its visibility gone or invisible. try this.
imageView = (TouchImageView) imageLayout.findViewById(R.id.imagenFullScreen);
info = (TextView) imageLayout.findViewById(R.id.textoInfoImagen);
imageView.setTag(info);
imageView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
TextView tv = (TextView)v.getTag();
tv.setVisibility(View.GONE);
}
Upvotes: 1
Reputation: 165
Toast.makeText(getBaseContext(), "CLICK", Toast.LENGTH_SHORT).show();
Upvotes: 0
Reputation: 7386
You can define the textview in oclick event like this
imageView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
TextView info = (TextView) imageLayout.findViewById(R.id.textoInfoImagen);
info.setVisibility(View.GONE);//or you can invisible,
}
});
Upvotes: 0
Reputation: 889
set info.setalpha(0.0f); //for invisible
set info.setalpha(1.0f); //for visible
Upvotes: 0
Reputation: 889
in your xml set ,
android:visibility="true"
//in textview
and in your activity,
info.setVisibility(View.INVISIBLE);
Upvotes: 0
Reputation: 1684
Instead of this
info.setVisibility(View.GONE);
use this:-
info.setVisibility(View.INVISIBLE);
Set Visibility to your textview in xml:-
<TextView
android:id="@+id/textoInfoImagen"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="@color/grisTransparente"
android:gravity="center_horizontal"
android:paddingBottom="3dp"
android:paddingTop="3dp"
android:text=""
**android:visibility="visible"**
android:textColor="@color/blanco"
android:textSize="13sp" />
Upvotes: 0