Imageview in my app - java

I want to show an image when certain condition is met in the code.
My code is:
if((times-prt)/1000000 >1000) {
prt=times;
pushdata((lightIn > 150 ? 1 : 0));
// Log.d("Light amount: %02f", lightIn+"getArraydata= "+getArraydata() +"getArraydata()"+matchPattern());
if(matchPattern()) {
ImageView imageView = (ImageView) findViewById(R.id.new_logo);
imageView.setImageResource(R.drawable.new_logo);
// finish();
// System.exit(0);
}
}
Pattern is matching but no picture is showing.
Please, help me.

If your image view has visibility set to INVISIBLE or GONE in your layout.xml file, you will also need to call:
imageView.setVisibility(View.VISIBLE);

Related

Popover hint for imageview

Please take a look at image.
I am littile bit confused how to implement this pop over view on an Image view. Actually the design is an stepper module. so once the user choose an option, the layout showing next step. So each step should have an Image View. I implemented the stepper layout, but have some confusion on how to set the popover on each steps. ie just below to the imageview.
generated dynamic image view for showing steps.
for (int i = 0; i < CreationData.size(); i++) {
imageContainer[i] = new ImageView(getContext());
imageContainer[i].setImageResource(getResId(i, 0));// 0 determines the state of the image icon.
LinearLayout.LayoutParams param = new LinearLayout.LayoutParams(100, 100);
imageContainer[i].setLayoutParams(param);
dividerLine[i] = new View(getContext());
dividerLine[i].setBackgroundColor(getResources().getColor(R.color.stepper_line_color));
}
.
Next I want to append the pop over to each image view
Maybe using setOnLongClickListener on the ImageView help you:
myImageView.setOnLongClickListener(new View.OnLongClickListener() {
#Override
public boolean onLongClick(View view) {
Toast.makeText(context,"Text to show", Toast.LENGTH_LONG).show();
return true;
}
});
In the xml set the ImageView long-clickable:
<ImageButton
...
android:longClickable="true"
/>
Or you can do the same via code:
myImageView.setLongClickable(true);

How to hide and show a layout on scrolling down a scroll view in Android?

I have a particular layout which consist a scroll view and an image which is at bottom of the activity. My question is that when I start scrolling up that image will not visible and when the scroll reach to top it is visible again.
I attached my image link so that you get the idea what I want.
You can achieve this easily with android support widget CoordinatorLayout.
Follow this post to hide/show the image based on scrolling.
You can learn more about coordinator layout here
scrollView.getViewTreeObserver().addOnScrollChangedListener(new ViewTreeObserver.OnScrollChangedListener() {
#Override
public void onScrollChanged() {
if (scrollView != null) {
if (scrollView.getChildAt(0).getBottom() <= (scrollView.getHeight() + scrollView.getScrollY())) {
relativeLayout.setVisibility(View.VISIBLE);
}
else {
relativeLayout.setVisibility(View.INVISIBLE);
}
}
}
});
Here is something that you should try out
ScrollView sv = (ScrollView)findViewById(R.id.scrl);
sv.scrollTo(0, sv.getTop());
and when it gets to top show the visibility of the image view as visible and in else part make it gone...

Unable to enter the if statement | Android Studio

I am trying to fade two images back and forth:
Image1 with an id of imageone
Image2 with an id of imagetwo
For both the images, I have linked onClick in UI properties to the onClick method in the below Java code.
After the launching the app, when I click on image1, it is supposed to fade out and image2 should fade IN.
After analysis, I determined that the flow is not entering the if statement and is always getting directed to else no matter what.
How can I solve this?
Why is the if statement if (view.getId() == R.id.imageone) not letting the flow inside it even though the entry condition view.getId() == R.id.imageone is true?
public class MainActivity extends AppCompatActivity {
public void onClick(View view) {
ImageView imageone = (ImageView) findViewById(R.id.imageone);
ImageView imagetwo = (ImageView) findViewById(R.id.imagetwo);
if (view.getId() == R.id.imageone) {
imageone.animate().alpha(0f).setDuration(2000);//image1 fade OUT
imagetwo.animate().alpha(1f).setDuration(2000);//image2 fade IN
} else {
imagetwo.animate().alpha(0f).setDuration(2000);//image2 fade OUT
imageone.animate().alpha(1f).setDuration(2000);//image1 fade IN
}
}
}
#Narendra Jadon : You are right ,The problem was with the layout. The image two was on top of image one. And i solved it by setting the image one on top of image 2. Thank you everyone for your help.

ImageView on again click

I want my ImageView to change it's drawable resource as it is pressed. The problem occurs when ImageView is pressed for the second time.
Let me explain, if ImageView is pressed first time, I want it to change from drawable A to drawable B. If ImageView is pressed again I want it to change from drawable B to drawable A.
That pressed again part is not working..
Here's my code:
public void imageViewBiljeskeNaListiCheckMarkMetoda(View view){
imageViewBiljeskeNaListiCheckMark = (ImageView) findViewById(R.id.imageViewBiljeskeNaListiCheckMark);
if (view == imageViewBiljeskeNaListiCheckMark){
imageViewBiljeskeNaListiCheckMark.setImageResource(R.drawable.ic_biljeske_obavljeno);
} else {
imageViewBiljeskeNaListiCheckMark.setImageResource(R.drawable.ic_biljeske_nije_obavljeno);
}
}
Remove this from the method....
You need to init the object once in the onCreate...
imageViewBiljeskeNaListiCheckMark = (ImageView) findViewById(R.id.imageViewBiljeskeNaListiCheckMark);
Then add a boolean variable to control the state of the view. .
public void imageViewBiljeskeNaListiCheckMarkMetoda(View view){
flag =!flag;
if (view == imageViewBiljeskeNaListiCheckMark){
if (flag) {imageViewBiljeskeNaListiCheckMark.setImageResource(R.drawable.ic_biljeske_obavljeno);
} else {
imageViewBiljeskeNaListiCheckMark.setImageResource(R.drawable.ic_biljeske_nije_obavljeno);
}
}
I sugggest to use the "tag" of the view, and keep in the tag the information you need (e.g. if the view is pressed or not)
http://developer.android.com/intl/es/reference/android/view/View.html#setTag(java.lang.Object)
Can't you just use a toggle method like this?
private void toggleDrawableOnClick(){
/* now you can check to see if the set drawable is A using its id */
if(visible drawable is A){
imageViewBiljeskeNaListiCheckMark.setImageResource(R.drawable.ic_biljeske_nije_obavljeno);
}else{
imageViewBiljeskeNaListiCheckMark.setImageResource(R.drawable.ic_biljeske_obavljeno);
}
}
This should be easier I believe!!

Android:imageview visibility and remove space between imageviews

Hi I am facing problem with the following scenarios
1) I have a common header with icons for all the screens..in one of the screen I have a list view ..when I click on the list it fires an intent ,it is a login screen and when i enter the password an icon should appear on the header...what i did is initially i made the icon invisible in layout and below is my login code..
ImageView imgView = (ImageView)findViewById(R.id.image1);
btnLogin.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
String password = etPassword.getText().toString();
if(password.equals("1234")){
lblResult.setText("password successful.");
imgView.setVisibility(View.VISIBLE);
} else {
lblResult.setText("wrong password");}
finish();}
but its not working..where I am wrong..
2) I have 4 images on header..and i set visibility on and off on middle icon ..when icon is invisible i want the remaining icons side by side ..but now i am getting a blank space between the icons how can i remove that space.
Any suggestions is appreciated.
now i am getting a blank space between the icons how can i remove that space.
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.

Categories