Android Java Context Binding like Javascript
In Java on Android when we code using this style
public void OnCreate开发者_高级运维(Bundle savedInstantState) {
SearchClass = (EditText) findViewById(R.id.SearchField);
SearchClass.addTextChangeListener(new TextWatcer() {
getData task = new getData(this);
}
}
When using this style of coding: How do I pass the context into the textchangelistener? (I call an asynctask with do something with 'this' but it requires the context to be passed properly.
In JavaScript you can do something similar to
SearchClass.AddTextChangeListener(new TextWatcher() { ..}).bind(this);
to solve the problem.
In your class declare
Context mContext;
Initialize it
mContext = this;
You can use it inside your private (inner) classes.
精彩评论