0

I am using SlidingMenu library provided by jfeinstein10, and I would like to inflate a certain number of linearlayouts with textviews in them ( each linking to one Activity inside my app). I would like to make the textview that starts current Activity be non-clickable, but for this, I have to create a condition where I can compare current Activity's context to the context of the Activity that created this SlidingMenu. I know it sounds quite complicated what I'm trying to explain, but I also feel like the solution could be quite simple. I`ll show a picture so you can understand better:

enter image description here

So I would like, ie Cart textView to be disabled for tapping, if current Activity (the one on the right) is Cart Activity.

I have to do something like this:

tv_menu_cart.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
             // check if Cart Activity's context is the current one and -> do nothing, otherwise continue with starting the activity.

            startActivity(new Intent(getBaseContext(), Cart.class));
            sm.toggle(false);
        }
    });
Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
DoruAdryan
  • 1,314
  • 3
  • 20
  • 35

1 Answers1

1

It is not quite clear to me what content you wrote. But seeing at your title, I guess you are trying to get the context.

If that is what you are looking for, there are few methods you can use:

 - getContext() 
 - getBaseContext() 
 - getApplicationContext()

I hope it helps.

openrijal
  • 583
  • 6
  • 22
  • on other note, you can get parent Activity by calling [Activity.html#getParent](http://developer.android.com/reference/android/app/Activity.html#getParent) – openrijal May 22 '13 at 11:48
  • I edit-ed my question so I would be more clear about what I'm asking about. – DoruAdryan May 22 '13 at 12:02
  • to compare your application contexts, you can first get the parent activity and get its application context like: `activity.getParent().getApplicationContext()` and compare it to the current context. – openrijal May 22 '13 at 12:10
  • it still beats me up.. given the next example: CartActivity extends BaseFragmentActivity, what would be the code for the desired condition inside BaseFragmentActivity class. Compare whom to whom? ( 'this' -> links to BaseFragmentActivity). – DoruAdryan May 22 '13 at 12:33