Skip to main content

Posts

Showing posts from December, 2017

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 SeekBarPreference in Android

There is no predefined SeekBarPreference in Android. But we can make our own SeekBarPreference very simply. Here is simple example of making and using SeekBarPreference in Android. SeekBarPreference.java public class SeekBarPreference extends Preference implements SeekBar.OnSeekBarChangeListener { private TextView textValue; public SeekBarPreference(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { super(context, attrs, defStyleAttr, defStyleRes); } public SeekBarPreference(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); } public SeekBarPreference(Context context, AttributeSet attrs) { super(context, attrs); } public SeekBarPreference(Context context) { super(context); } @Override protected View onCreateView(ViewGroup parent) { super.onCreateView(parent); View view = LayoutInflater.from(getContext()).inflate(R.layou

Simple example of Using JobScheduler in Android

JobScheduler is the Android framework API for scheduling tasks or work. It first became available in Android 5.0 (API level 21), and remains under active development. Notably, Android 7.0 (API level 24) added the ability to trigger jobs based on ContentProvider changes. If your app targets Android 5.0 (API level 21), we recommend that you use the JobScheduler to execute background tasks. Here is the simple example of Scheduling and Cancelling the scheduled job. MainActivity.java public class MainActivity extends AppCompatActivity { int count; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); Toolbar toolbar = findViewById(R.id.toolbar); setSupportActionBar(toolbar); } public void addJob(View view) { count++; JobScheduler scheduler = (JobScheduler) getSystemService(Context.JOB_SCHEDULER_SERVICE); ComponentName comp

Simple example of using ViewPager in Kotlin | Android

Though Kotlin has lot of massive features to speedup the development time, here is the simple example of using ViewPager in Android. In Kotlin we don't need to declare and initialize Views. We can simply access the id of Views from xml. Ex: activity_main.xml &lt?xml version="1.0" encoding="utf-8"?&gt &ltandroid.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context="com.guna.kotlinapplication.MainActivity"&gt &ltandroid.support.design.widget.AppBarLayout android:id="@+id/appBarLayout" android:layout_width="match_parent" android:layout_height="wrap_content" android:the