If-else statement for images.setvisibilty - android

i wanna ask about how can i do an if-statement using the code below? I have tried it and it give me an error; its say cannot convert void to bool. any suggestion?
if(images.setVisibility(View.GONE)){
Display();
}

You need to get visibilty and check it..
if(images.getVisibility()==View.GONE){
Display();
}

You can simply use below of the two codes:
if(images.getVisibility==view.GONE)
{
Display();
}
the getVisibility() returns an integer.
you can also check with the integer code
i.e.
VISIBLE-0
GONE-8
INVISIBLE-4
2.
if(images.getVisibility==0)
//VISIBLE
if(images.getVisibility==4)
//INVISIBLE
if(images.getVisibility==8)
//GONE

Try this:
if(images.getVisibility()==View.GONE){
Display();
}

Make sure in your code, images.setVisibility() images must be instance of View. then use View.getVisibility() method
if(images.getVisibility() == View.GONE)
Display();

Related

I want to make a for loop, but it won't compile

for(sudoku.get((int)(0)).doubleValue(); == sudoku.get((int)(1)).doubleValue();) {
sudoku.remove((int)(1));
Sudoku.add(Double.valueOf(SketchwareUtil.get random((int)(1)),
((int)(9))));
}
The error wants me to remove the "==" in the condition.
This is the first time I have tried to use "for" for something that isn't a repeat a set amount of time.
I think that there is small typo mistake in semicolon :
for(; sudoku.get((int)(0)).doubleValue() == sudoku.get((int)(1)).doubleValue();) {
sudoku.remove((int)(1));
Sudoku.add(Double.valueOf(SketchwareUtil.get random((int)(1)),
((int)(9))));
}

How can i show 2 position value as default in spinner

Like i have 10 values in Spinner (0-9 positions). What if i would like to show 2 position value as default in spinner in onCreate()...
By seeing your code from your link you haven't called adapter.notifyDataSetChanged().Please check that. You should call it in the postExecute() method
And also please use .equals() to check String values instead of ==. That may be your issue.
if(strPHPCity.equals("Delhi")) {
spinnerCity.setSelection(0);
} else if (strPHPCity.equals("Banglore")) {
spinnerCity.setSelection(1);
}
As pointed out by other guys you are creating your spinner adapter using cityArrayList but you are not adding any item to this ArrayList. This is the reason your spinner is blank. You should refresh your adapter once data is available.
This is how you should do it.
protected void onPostExecute(Boolean result) {
if(result == false)
Toast.makeText(getApplicationContext(), "Unable to fetch data from server", Toast.LENGTH_LONG).show();
else {
adapter.notifyDataSetChanged();
mySpinner.setSelection(2)
}
}

scrollTo not working

I am requesting help. Here is the code
scrollView = (ScrollView)findViewById(R.id.scrollview4201);
if (scrollview_f_check.contains("1"))
{
scrollView.scrollTo(0, +2000);
scrollview_f_check = "0";
SharedPreferences.Editor editor=mUserSettings.edit();
editor.putString(USER_PREFERENCES_SCROLLVIEW4201, scrollview_f_check);
editor.commit();
Toast.makeText(getApplicationContext(), "scrollview_f_check = " + String.valueOf(scrollview_f_check), Toast.LENGTH_SHORT).show();
}
I have verified using the toast that correct variable is passing through the if statement. So the issue lies completely with "scrollView.scrollTo(0, +2000);" line.
Why would this not work?
Part 2: I also tried to use the .getleft() and .getTop() of the exact TextView I wanted to use, but it always came back with 0 for both.
Also you can try using scrollTo() method in onWindowFocusChanged() method instead of onCreate().

Comparing the background resources of buttons

button.setBackgroundResource(R.Drawable.abc);
if ( button.getBackground()==getResources().getDrawable(R.drawable.abc))
{
button.setBackgroundResource(R.drawable.xyz);
}
else if( button.getBackground()==getResources().getDrawable(R.drawable.xyz) )
{
button.setBackgroundResource(R.drawable.abc);
}
I want to compare the background images set on the button. The above code has been taken from Stack Overflow... but it doesn't seem to work
Please suggest a better method.
Try this
if ( button.getBackground().getConstantState()==getResources().getDrawable(R.drawable.abc).getConstantState())
{
button.setBackgroundResource(R.drawable.xyz);
}

Remove the background of a textview

I set a background for a textview and I want to remove it dynamically but it dosen't work,
are there any suggestion?
if (mToday) {
monthView[mRow][mColumn].setBackgroundResource(R.color.black);
}
else {
monthView[mRow][mColumn].setBackgroundResource(0);
}
I found a reasonable explanation here why it is happen, but again didn't solve the problem.
try this.
txtEmail.setBackgroundResource(android.R.color.transparent);
try the following code just changed 0 to null in .setBackgroundDrawable thats all it will work check once :
if (mToday)
{
monthView[mRow][mColumn].setBackgroundResource(R.color.black);
}
else
{
monthView[mRow][mColumn].setBackgroundDrawable(null);
}
I think this should work
monthView[mRow][mColumn].setBackgroundDrawable(null);

Categories

Resources