firing an Event by code in android
<p>Wondering if there is any way to build and fire an event (e.g. on click event) in android applications programmatically. </p>

<p>Thanks.</p>

<p>sorry, it seems question is not clear enough, let me explain a bit more:</p>

<ul>
<li>I have an Activity (lets call it A) with multiple views (5 ImageView for example).</li>
<li>And a normal Java class (lets call it B) which is used by my Activity.</li>
<li>There is an instance of B in my Activity. </li>
<li>If user click on a View (Image View) the view OnClickListener calls a method in B  </li>
<li>In B, if operation is successful, it will call back a method in activity again. </li>
<li>in activity method, It will change image or state for clicked ImageView.</li>
</ul>

<p>in the other hand:</p>

<p>click on view (x) in Activity -------> B.doSomething() --------> A.bIsDone() -----> change image for view (x) </p>

<p>with normal execution, its working and there is no problem.</p>

<p>the problem is that I want to simulate this process to be automatic, my code looks like this:</p>

<pre><code>        while (!b.isFinished()) {
            try {
                b.doSomething(&lt;for View x&gt;);
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }           
</code></pre>

<p>The issue is that, it won't render anything, until the end of the loop. </p>

<p>I tried to put the loop in another Thread, but its throwing exception:</p>

<pre><code> android.view.ViewRoot$CalledFromWrongThreadException: Only the original thread that created a view hierarchy can touch its views.
</code></pre>

<p>what can i do for this issue? i was think generate an click event on view (by code), to see it can help or not.</p>

<p>what is your solution?
Thanks </p>
