Reputation: 819
I have set the visibility of imageView as gone by default.
Now, I want to make it visible when the the below(my code) condition goes true.I have checked that the condition goes true and my code setVisibility(View.VISIBLE) also executes but there is no any change on my UI.
@Override
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
addBottomDots(position);
if(position == layouts.length-1){
imageView.setVisibility(View.VISIBLE);
imageView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
startActivity(new Intent(MainActivity.this,AlarmActivity.class));
}
});
}
}
XML of my ImageView
<ImageView
android:id="@+id/startImageView"
android:layout_width="80dp"
android:layout_height="40dp"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:visibility="gone"
app:srcCompat="@drawable/starthere" />
Problem: After execution of my code the visibility is not changing means it remain invisible
Upvotes: 1
Views: 5349
Reputation: 1781
Can you follow below steps and let me know..
Remove visibility code from xml file
. Put below code after setContentview
.
imageView.setVisibility(View.INVISIBLE);
Now if you want to visible the imageView
again please put below code in your click listener
.
imageView.setVisibility(View.VISIBLE);
This should work for you. It works because there is difference between visibility gone
and visibility invisible
View.GONE
: This view is invisible, and it doesn't take any space for layout purposes.
View.INVISIBLE
: This view is invisible, but it still takes up space for layout purposes.
Upvotes: 2
Reputation: 4234
The problem is, that you don't use the UI Thread:
Activity act = (Activity)context;
act.runOnUiThread(new Runnable(){
@Override
public void run() {
-----
imageView.setVisibility(View.VISIBLE);
imageView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
startActivity(new Intent(MainActivity.this,AlarmActivity.class));
}
});
-----
} });
Upvotes: 2