Common Issues
ViewPager PagerAdapter not updating the View
1 2 3 |
public int getItemPosition(Object object) { return POSITION_NONE; } |
ViewPager PagerAdapter not updating the View
1 2 3 |
public int getItemPosition(Object object) { return POSITION_NONE; } |
There are several ways to achieve this. The first option is easier, but bit more inefficient. Override getItemPosition in your PagerAdapter like this:
1 2 3 |
public int getItemPosition(Object object) { return POSITION_NONE; } |
This way, when you call notifyDataSetChanged(), the view pager will remove all views and reload them all. As so the reload effect is obtained. The second option, suggested by Alvaro Luis Bustamante (previously alvarolb), is to setTag()method in instantiateItem() when […]
You can do this by translating and scaling the content View in the onDrawerSlide() method of a DrawerListener on your DrawerLayout. Since the content View itself is resizing, and there’s a separate TextView that appears in the bottom right corner, we’ll stick both of these in another holder ViewGroup. If that label TextView isn’t needed, the holder ViewGroup can be omitted, as well. A basic DrawerLayout setup for the example:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/drawer_layout" android:layout_width="match_parent" android:layout_height="match_parent" android:background="#222222"> <RelativeLayout android:id="@+id/holder" android:layout_width="match_parent" android:layout_height="match_parent"> <LinearLayout android:id="@+id/content" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> <android.support.v7.widget.Toolbar android:id="@+id/toolbar" android:layout_width="match_parent" android:layout_height="?attr/actionBarSize" android:background="#E97411" /> <ImageView android:id="@+id/main_content" android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="1" android:background="#EEEEEE" android:src="@drawable/ic_launcher" /> </LinearLayout> <TextView android:id="@+id/label" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:layout_alignParentRight="true" android:visibility="gone" android:textSize="26dp" android:text="My App" /> </RelativeLayout> <android.support.design.widget.NavigationView android:id="@+id/navigation_view" android:layout_width="240dp" android:layout_height="match_parent" android:layout_gravity="left" android:background="#555555" /> </android.support.v4.widget.DrawerLayout> |
The […]
With the advent of Android Lollipop, the RecyclerView made its way officially. The RecyclerView is much more powerful, flexible and a major enhancement over ListView. I will try to give you a detailed insight into it. Advantages 1) ViewHolder Pattern In a ListView, it was recommended to use the ViewHolder pattern but it was never a compulsion. In […]
1 2 3 4 5 6 7 |
private void addToChild(String label, String value) { LinearLayout item = findViewById(R.id.dataWrapper);//ViewGroup where we need to append views View child = getLayoutInflater().inflate(R.layout.model_dialog_row, null); //Layout which we need to add ((TextView) child.findViewById(R.id.modelDialogRowLabel)).setText(label); ((TextView) child.findViewById(R.id.modelDialogRowValue)).setText(value); item.addView(child); } |
Splash Screen In this quick tutorial we will see how to implement a Video Splash Screen in your app. Splash Screens are normally shown for a few seconds as a progress while the app is ‘booting up’ i.e performing a version check or initialising the Analytics etc. Sometimes the Splash Screen is also used to showcase the app […]
Actually Android Studio isn’t showing you an “error message”, it’s just a warning. Some answers propose the use of an assertion, Dalvik runtime has assertion turned off by default, so you have to actually turn it on for it to actually do something. In this case (assertion is turned off), what you’re essentially doing is just tricking […]
If you are looking for delete cache of your own application then simply delete your cache directory and its all done !
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
public static void deleteCache(Context context) { try { File dir = context.getCacheDir(); deleteDir(dir); } catch (Exception e) {} } public static boolean deleteDir(File dir) { if (dir != null && dir.isDirectory()) { String[] children = dir.list(); for (int i = 0; i < children.length; i++) { boolean success = deleteDir(new File(dir, children[i])); if (!success) { return false; } } return dir.delete(); } else if(dir!= null && dir.isFile()) { return dir.delete(); } else { return false; } } |
And you may require following permission to add in your manifest file in order to delete cache of other application
1 |
<uses-permission android:name="android.permission.CLEAR_APP_CACHE"/> |
Android Thread Constructs(Part 4): Comparisons In this series of posts we have seen the following thread constructs: 1. Basic threads and communication between them [see article] 2. Understanding the Main thread or the UI thread [see article] 3. IntentService [see article] 4. AsyncTask [see article] NOTE: These are Android specific constructs. Android also includes the […]
What is View? View class represents the basic building block for user interface components. A View occupies a rectangular area on the screen and is responsible for drawing and event handling. View is the base class for widgets, which are used to create interactive UI components (buttons, text fields, etc.). The ViewGroup subclass is the […]