How to access Activity UI from my class?
see you post, i've edited it , to fix the problem
hope it helps :=)
here is the Edit :
file MyActivity.java:
public class MyActivity extends Activity {
TextView myView ;
protected void onCreate(android.os.Bundle savedInstanceState) {
myView = (TextView)findViewById(R.id.myView);
Points myPoints = new Points(this);
myPoints.displayMsg("Hello World !!!");
}
}
--------------------------------------------------------------
file Points.java:
private class Points {
protected MyActivity context;
//add a constructor with the Context of your activity
public Points(MyActivity _context){
context = _context;
}
public void displayMsg( final String msg){
context.runOnUiThread(new Runnable() {
@Override
public void run() {
context.myView.setText(msg);
}
});
}
}
- Your
Points
can't be a private class without being an inner class. So your code doesn't even compile... -
Pass the view as parameter to the constructor of your
Points
class:public class MyActivity extends Activity { TextView myView = (TextView)findViewById(R.id.myView); Points myPoints new Points(myView); private class Points { public Points(TextView view) { // todo } } }