tags:

views:

57

answers:

1

HI all, this is my class A, where on button click , i m sending a int variable to class B

Intent bgIntent = new Intent(Background.this, MainScreen.class);
bgIntent.putExtra("background",  bgColor);
startActivity(bgIntent);

and on class B

Intent bgIntent = getIntent();
bgGlobal = bgIntent.getIntExtra("background",-1 );

if(bgGlobal == 0) 
{
   DetailsTextView.setBackgroundResource(R.color.a0);
}
else 
    if(bgGlobal == 1)
    {
        DetailsTextView.setBackgroundResource(R.color.a1);
    }

But the problem is i am getting a blank view.My view is not coming up with textview. is this proper to set background

"DetailsTextView.setBackgroundResource"???

A: 

If you want to change the color of a View use http://developer.android.com/reference/android/view/View.html#setBackgroundColor(int)

for example:

DetailsTextView.setBackgroundColor(getResources().getColor(R.color.txt_green));

Anyway, it's not clear if you want to change the screen's background or the textview's background.

Also

if(bgGlobal == 0){...} else ...

is wrong. You should do something of the like

if(bgGlobal != -1)
{
 [Use intent to read color]
}else{
 [set default color]
}

If you see a blank view it's possibly due to a wrong XML layout.

Edit: To retrieve the extra

getIntent().getExtras().getInt("background",-1);
Maragues
Thanks MaraguesI want to change textview's background.Well my xml is f9, there is no problem wid that.
shishir.bobby
Am i passing and retriving "bgcolor" correctly??
shishir.bobby
I've answered the question in the answer, check the last 2 lines
Maragues
hey Maraguescan i change directly background color of textview, which is in class B, from class A?? without passing intent.
shishir.bobby
Why would you want to do that? You'll only see the background of the textview if the activity is in the foreground, and the activity B will be in the foreground if started from the activity A, right?Anyway, there's a way to do it using BroadcastReceiver and some other things, but that's out of the scope of this question.Please accept the answer if you consider it solved your problem. Good luck!
Maragues