Remove the background of a textview - android

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);

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))));
}

Set correct and incorrect buttons' templates simultaneously

I am having a method, handling the correct/incorrect answers entered in a quiz game:
public void answerButtonClickHandler(View v)
{
Answer answer = myAnswers.get(v.getId());
if (answer != null)
{
myQuestionsAnswered++;
if (answer.isCorrect())
{
myCorrectlyAnswered++;
v.setBackgroundResource(R.drawable.answer_button_correct);
}
else
{
v.setBackgroundResource(R.drawable.answer_button_incorrect);
}
}
What it is doing so far is to check if the answer is correct or not (this part works fine) and sets a corresponding template. What I'd want to add as functionality is when the wrong answer is marked, the correct one to be marked as well. I was trying to keep the state of the vies (v) in a new View variable, in both of the states, but have not done the trick so far. Thanks you!

How to check if a Checkbox is checked?

I have two check boxes,and I want to set tag as per its selection or check status,so can any one tell me how to set tags in my application,the following is my code tell me my mistakes,..
if(matchcheck.isChecked())//checked then
{
matchcheck.setTag("N1");//set No 1..
}
else
{
matchcheck.setTag("Y1");//set yes 1
}
if(newsletter.isChecked())
{
newsletter.setTag("N2");//set no 2
}
else
{
newsletter.setTag("Y2");//set yes 2
}
I think you are just setting the opposite of what you want.
if(matchcheck.isChecked())//checked then
{
matchcheck.setTag("Y1");//set yes 1
}
else
{
matchcheck.setTag("N1");//set No 1
}
if(newsletter.isChecked())
{
newsletter.setTag("Y2");//set yes 2
}
else
{
newsletter.setTag("N2");//set no 2
}
Should be your code.
But anyway, consider using RadioButtons and giving them the look and feel you want. It will be easier, they are intended for these kind of situations.

If-else statement for images.setvisibilty

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();

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);
}

Categories

Resources