Ameen Majeed
Ameen Majeed

Reputation: 21

accessing activity variables from View

I Have an android activity with a custom view set to it. I need to access some activity variables in my View class. How can I do this?

Upvotes: 1

Views: 662

Answers (1)

snachmsm
snachmsm

Reputation: 19273

your View should have Activity's context, so inside your CustomView

((MyActivity) getContext()).executeCustomMethod();

if you adding View in xml you can use for main parent view lines like this

xmlns:tools="http://schemas.android.com/tools"
tools:context="com.example.test.MyActivity"

Upvotes: 1

Related Questions