I have some questions about android ui api.
Give a example, that I want to implement.
Main_UI_Thread.java :
public class Main_UI_Thread extends Activity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
/*** do something about layout ***/
...
DisplayClass dc = new DisplayClass();
Thread th = new Thread(dc);
th.start();
}
}
DisplayClass.java :
public class DisplayClass extends Thread{
@Override
public void run() {
if( something happen ) {
to display Dialog or Toast show
and handle the ui listener
}
}
}
I know the message passing can be do that;
But I want the ui program is be implemented in DisplayClass.java
Is it possible??
My English is not well.^^”
Thanks everybody to give me some suggestions. 😛
Your
DisplayClasswould probably need a reference to yourActivityinstance, and modify the UI by calling theActivity‘s methods (or UI modifying methods that accept theActivityinstance as an argument).Also, remember to always use the
runOnUiThreadmethod to perform UI modifying actions from your “own” threads.No need for DisplayClass to extend
Threadif you are doingnew Thread(dc);. Implementing Runnable is good enough.