java


How not to lose focus?


I have a Video Player using library and On him ImageView, ie the type of banner that covers 30% of the video player. Every 15 seconds, the picture should change.
mBannerView.setImageBitmap (BitmapFactory.decodeFile (file.getAbsolutePath ()));
Thread.sleep (1000 * 15);
But I have a crash when changing the picture with the message:
Android "Only the original thread that created a view hierarchy can
Touch its views. "
I tried to write these lines to UI stream:
    
runOnUiThread (new Runnable () {
        #Override
        public void run () {
            ............
        }
    });
ImageView but then does not respond to any timer or change.
I think right now (maybe wrong, in this case, please correct) that the focus is on the video player as the video plays, and so the picture above it is changed, crashes down.
If so, how in that case,
how not to lose focus with ImageView while and continued to play a video?
And if not, what could be wrong?
UPD: code:
public void bannerSlide(boolean run) {
Timer timer = new Timer();
File file;
if (run){
mBannerView.setVisibility(View.VISIBLE);
final List<Banner> bannerList = GlobalData.loadBannerInfo(MainActivity.this);
if (bannerList != null && bannerList.size() > 0){
for (int i = 0; i < bannerList.size(); i++){
file = new File(Application.banner_path + bannerList.get(i).getName());
if (file.exists()){
mBannerView.setImageBitmap(BitmapFactory.decodeFile(file.getAbsolutePath()));
}
final int finalI = i;
timer.schedule(new TimerTask() {
#Override
public void run() {
if (finalI == bannerList.size() - 1){
bannerSlide(true);
}
}
}, 15 * 1000);
}
} else {
mBannerView.setVisibility(View.GONE);
}
} else {
mBannerView.setVisibility(View.GONE);
timer.cancel();
}
}
This does nothing with the focus. You MUST NOT touch UI widgets from other threads than UI thread. And there's no exception. runOnUiThread() should come as solution as you guessed but while you show no code that you run it's hard to say what you did wrong there.

Related Links

Regex Between word
Identifying Search Crawler
where to instantiate simple values /entity objects? DDD
exception in thread awt-eventqueue-0 java.lang.nullpointerexception error for checkbox in jtable [duplicate]
Highlighting keywords in JTextArea (Netbeans)
Rectifying SOAP exception with java
jsTree, need to expand all the nodes when refreshing
User login fails when using password encoding in Spring
Which data structure to use for storage of matrix pairs?
how do i add 3 salaries using array index?
Android Studio Rendering problems Classes coudnt be instantiated
Stacks and Queues ferry simulator
Custom listview don't work
Why is SHA256withRSA Signature Different when Computed Byte-by-Byte versus All at Once?
Should I keep my listeners and layout variables in separate class [closed]
In Android Studio, cannot invoke Activity B from Activity A more than once

Categories

HOME
sendgrid
image
jdo
netsuite
netbeans
dictionary
react-redux
jgroups
binary-tree
win32gui
icloud
datastax-java-driver
android-youtube-api
cross-validation
cloudkit
primary-key
dax
flask-wtforms
ghc
transformation
sms-gateway
opencover
jquery-ajaxq
functional-testing
bootstrap-tour
windows-error-reporting
social-media
wtx
instant-messaging
iframe-resizer
bosh
galsim
exuberant-ctags
language-concepts
mapdb
jquery-bootgrid
hot-module-replacement
xenforo
webix-treetable
impersonation
ansible-playbook
quadratic-programming
botbuilder
firebase-admin
mime
acoustics
scrollable
revapi
zip4j
promela
drupal-6
sqlclient
lift-json
iso8601
jspdf-autotable
watchconnectivity
url-pattern
static-ip-address
angular-cache
httplistener
rotativa
log4c
mathematica-frontend
bstr
ready-api
photobucket
feedback
android-listview
twirl
method-parameters
sankey-diagram
sniffer
ami
composite
c3
angularjs-ng-click
issuu
starcluster
expected-exception
mcts
gridfs
ftps
pygit2
drools-planner
itmstransporter
amazon-appstore
transactionscope
adk
gnu-prolog
coredump
netbeans-7.1
nsviewanimation
simpletest
commodore
rtml

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App