Case:
Fragment inside xml.
Use of view is to use with RecyclerView viewholder.
Sometimes strange RuntimeException occurs: android.content.res.Resources$NotFoundException: Unable to find resource ID ...
XML looks like this:
...
<someviewgroup android:layout_height="wrap_content" android:layout_width="wrap_content">
<fragment android:id="+@id/someId" android:layout_height="100dp" android:layout_width="100dp" android:name="bla.bla.YourFragment">
</fragment></someviewgroup>
...
If you inflate this XML you can face with android.content.res.Resources$NotFoundException.
And stacktrace guides to nowhere:
E/AndroidRuntime(1013): FATAL EXCEPTION: main
E/AndroidRuntime(1013): android.content.res.Resources$NotFoundException: Unable to find resource ID #0xffffffff
E/AndroidRuntime(1013): at android.content.res.Resources.getResourceName(Resources.java:1659)
E/AndroidRuntime(1013): at android.support.v4.app.FragmentManagerImpl ...... and etc.
The only way (I could find) to fix crash is to remove id.
But how to get access to instance of Fragment bla.bla.YourFragment from ViewHolder?
You cannot find fragment by id or tag.
Solution is:
In your fragment add callback as tag to rootview:
public void onViewCreated(View view, Bundle savedInstanceState) {
view .setTag(new SomeHandler() {
@Override
public void someMethod() {
//Some code
}
});
}
In ViewHolder find that View and get tag (there is no need to explain how to do it).
Voila, you can pass almost any data into your Fragment!
Thursday, February 11, 2016
Wednesday, February 10, 2016
Friday, October 16, 2015
SQL commands for Android sqlite
SQL commands for Android sqlite
| ifnull(X,Y) | The ifnull() function returns a copy of its first non-NULL argument, or NULL if both arguments are NULL. Ifnull() must have exactly 2 arguments. The ifnull() function is equivalent to coalesce() with two arguments. |
and etc.
Monday, September 28, 2015
Install google services on AVD
http://inthecheesefactory.com/blog/how-to-install-google-services-on-genymotion/en
Saturday, September 12, 2015
If geny doesn't start under Ubuntu
If you use Linux, make sure that the dkms package is installed and that it compiles VirtualBox kernel modules each time a new kernel update is available. To do so, run
sudo /etc/init.d/vboxdrv status
You should get the message VirtualBox kernel modules (vboxdrv, vboxnetflt, vboxnetadp, vboxpci) are loaded.
If not, force VirtualBox kernel modules compilation by running
sudo /etc/init.d/vboxdrv setup
Make also sure that you are part of the "vboxusers" group. If not, run
sudo usermod -a -G vboxusers <login>
https://www.genymotion.com/#!/support?chapter=vbox#faq
sudo /etc/init.d/vboxdrv status
You should get the message VirtualBox kernel modules (vboxdrv, vboxnetflt, vboxnetadp, vboxpci) are loaded.
If not, force VirtualBox kernel modules compilation by running
sudo /etc/init.d/vboxdrv setup
Make also sure that you are part of the "vboxusers" group. If not, run
sudo usermod -a -G vboxusers <login>
https://www.genymotion.com/#!/support?chapter=vbox#faq
Monday, September 7, 2015
Thursday, September 3, 2015
Выполнение AsyncTask - onPostExecute не выполняется
Интересный случай.
AsyncTask запускается внутри View.
Фоновая работа проходит успешно, но метод onPostExecute или выполняется через неприлично долгое время или вообще не выполняется.
Решение - создавать и запускать AsyncTask в методе post объекта android.os.Handler, полученного в Application.
Вынести создание таска в активити.
upd. RxJava
AsyncTask запускается внутри View.
Фоновая работа проходит успешно, но метод onPostExecute или выполняется через неприлично долгое время или вообще не выполняется.
Вынести создание таска в активити.
upd. RxJava
Subscribe to:
Posts (Atom)