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

How can I exit out of this loop?
Add comboBox at Kendo
Pass in more than just WebDriver to the constructor for PageFactory?
Android studio SQLite delete button not working - SQLiteException: near “?”: syntax error (code 1):
Inheritance and Static Nested Java Classes
Maven not found while using Gitlab-ci-multi-runner
Is there a way to use Jetty (or Tomcat)'s servlet's engine only (remove all JSP functionality)?
Java Scanner(System.in) does not open file after user input
Does Spring Data MongoDB supports MongoDB 3.4 collation feature?
maven dependency - 3 projects and 1 framework project dependency not be including
if i select distance in one combobox than distance units will be displayed in another combobox ,similarly with currency [duplicate]
Why ArrayIndexOutOfBound Exception can be caught in Java, but C++ program crashes instead? [duplicate]
Checking values inside an Array List
Receiving a differnet HttpServletRequest from the same client?
Perisistence Exception : No Persistence provider for EntityManager named defaultPersistenceUnit
HashSet<List<Integer>> time complexity

Categories

HOME
compiler-construction
yii2
log4j
multithreading
vbscript
smarty
relative-path
vmware
kalman-filter
yarn
jpeg
autotools
virtualization
spring-xd
offline
u-sql
timeout
dtrace
fortumo
jsprit
uitypeeditor
tostring
pc
cloudhub
icloud-api
crosstab
angular2-aot
sparse-matrix
apache-commons-io
rst2pdf
applozic
subdomains
google-cloud-nl
google-rich-snippets
usbserial
dosbox
xcode-extension
ssjs
greenrobot-eventbus
graphenedb
particles.js
preconditions
hp-ux
gzipstream
dynamic-reports
fakeiteasy
modelmapper
qwt
fault
strptime
atomicity
dotnetzip
fancybox-2
tizen-native-app
rdfs
gabor-filter
crypt
sqldf
orthogonal
blacklist
crosswalk-runtime
gridpane
mathematica-frontend
impresspages
connect-by
markojs
itextpdf
associative-array
lemon
ruby-2.2
django-unittest
security-testing
myo
unity3d-gui
census
key-management
mbr
google-cloud-save
quartz-graphics
flash-builder4.5
padarn
distutils
jquery-knob
funscript
nsmanagedobject
iphone-web-app
radcombobox
dmx512
libs
backcolor
mtj
phonon
procedural-music
ntvdm.exe

Resources

Database Users
RDBMS discuss
Database Dev&Adm
javascript
java
csharp
php
android
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App