Skip to main content

Posts

Showing posts from October, 2018

Featured post

Simple RecyclerView example with filter option in Android

Hi Guys, Maybe you all are expert in terms of using RecyclerView in android. This blog is simple example for using filter option with RecyclerView adapter. As for now you will instantiate RecyclerView and set the adapter to RecyclerView as following way. RecyclerView list = (RecyclerView) findViewById(R.id.list); list.setLayoutManager(new LinearLayoutManager(this)); list.setHasFixedSize(true); ArrayList&ltNumber&gt numbers = new ArrayList&lt&gt(); String ONEs[] = {"ZERO", "ONE", "TWO", "THREE", "FOUR", "FIVE", "SIX", "SEVEN", "EIGHT", "NINE", "TEN"}; String TENs[] = {"ZERO", "TEN", "TWENTY", "THIRTY", "FOURTY", "FIFTY", "SIXTY", "SEVENTY", "EIGHTY", "NINETY", "HUNDRED"}; String HUNDREDS[] = {"ZERO", "HUNDRED", "TWO HUND...

Simple example of DraggableTextView in Android | Kotlin

Hello All, By using simple onTouch event we make an DraggableTextView widget. Here is the code sample for you. override fun onTouch(v: View?, event: MotionEvent?): Boolean { val x = event?.rawX?.toInt()!! val y = event.rawY.toInt() when (event.action) { MotionEvent.ACTION_DOWN -> { val layoutParams = layoutParams as ConstraintLayout.LayoutParams xDelta = x - layoutParams.leftMargin yDelta = y - layoutParams.topMargin rect.set(0, 0, width, height) isDragging = true } MotionEvent.ACTION_MOVE -> { val layoutParams = layoutParams as ConstraintLayout.LayoutParams layoutParams.leftMargin = x - xDelta layoutParams.topMargin = y - yDelta setLayoutParams(layoutParams) } MotionEvent.ACTION_UP -> { isDragging = false } } invalidate() return true } Here is the full video tutorial. Interesting...

Using shuffle from Collections in Java | Android

From Doc shuffle is used to Randomly permutes the specified list using a default source of randomness. All permutations occur with approximately equal likelihood. Here is the simple example of shuffle from collections. List numbers = new ArrayList (); for (int i = 0; i Output: Original List: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10] Shuffled List: [2, 10, 0, 3, 7, 5, 1, 9, 8, 6, 4] There is also public static void shuffle(List list, Random rnd) which will Randomly permute the specified list using the specified source of randomness. Interesting right? If you are really interested in this example, then please share this post with your friends, also share your feedback as comment here. Thank You