开发者

android get current activity's name for polymorphic method

开发者 https://www.devze.com 2023-02-25 03:05 出处:网络
I have a dilemma, basically I have ImageButtons that I want to be displayed on all activities (this is done) and I also want them to be displayed on all activities a certain way, depending on which ac

I have a dilemma, basically I have ImageButtons that I want to be displayed on all activities (this is done) and I also want them to be displayed on all activities a certain way, depending on which activity is being displayed. I want this to be done in a way that I don't have to hardcode the specifications individually in each class.

Although the images are defined in one shared XML document, I want a shared class to be able to read which activity is being called, and then format a particular image a certain way. This is so if I change the functionality, I on开发者_如何学JAVAly have to change attributes in one class.

I want to do some sort of If or switch statement that compares if( thisActivity == MainActivity ) then, but I don't know how to retrieve the "names" of the activities to compare them!

edit. I want something like this:

   Context myContext = this;

    if(myContext instanceof Intent(MainMenu.class) == true)
    {

    }

I know the Intent function doesn't have a prototype to check a class like that, but I want something that will let me know the current class is part of a particular class, as opposed to several other cases in the conditional statement

thank you for any insight!


Will the instanceof operator suit your needs?

if(this instanceof Activity1) {
//...
}
else if(this instanceof Activity2) {
//...
}
0

精彩评论

暂无评论...
验证码 换一张
取 消