Skip to main content

Posts

Using a list fragment with cursor adapter

All these days, I avoided using fragments. But then I realized for my this particular applications fragments are ideal. I have a master - detail list in my app.
Let us say you want to have two fragments - one is a fragment which contains a list of elements and second one expands one element of the list. Both of them share the same cursor from the activity.

Let us start with list fragment.

Do not try creating list fragment using a wizard. It unnecearrily adds too many methods and classes.

Let us start writing our own fragment like this

classMyListFragmentextends ListFragment{}
Next using code menu override option, override the following method

onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)

This method should be used for inflating the layout file for the fragment.  I have a framelayout in parent activity of this fragment with the id as container. So I will specify that for inflating. The framelayout will be the parent viewgroup for fragment. 


@Overrid…
Recent posts

Financial Calculator published

Today I have published my 7th app Financial Calculator in google play. (you will see 8 apps in market page. But Kannada Hindi keyboard is no longer supported as Akshara keyboard is its successor.)

This app is meant for us Indians who want to save our money a little bit in FDs and RDs. Or/and pay EMI each month for housing and other loans. The app can calculate EMI amount, FD or RD maturity value. (So you can correct the bank official if they make a mistake :) )

It will also calculate how much will you pay extra for the loan. It lets you compare two loans, compare two FDs or RDs.

There are other calculations too. Gratuity calculator, loan afford
ability calculator, savings goal calculator and currency converter.

So what are you waiting for? Download app today and give me your valuable feedback.


Ratings and feedbacks

Once your android project is at the finishing stage, you need to add the following extra features to your app.
Rate the appBecause rates drive app download Other apps by youfree advertisement for your apps Send feedbackyou need them to remove bugs and improve the app Well, I personally feel that the pop up screens which ask the user to rate the app, is not a good idea. People may get irritated by this.

But to provide the first one, you need to know the playstore page of your app. How do you get the page if you have not yet published the page?

Well, the app page always looks like this

https://play.google.com/store/apps/details?id=your_app_package_name



 the last part is your package name of the app.

And to take the user to all apps by you, you need to use a url like this

https://play.google.com/store/apps/developer?id=yourdevelopername

 So these two settled, let us write our xml and code


<?xml version="1.0" encoding="utf-8"?><menuxmlns:android="http://sch…

Using spinners in android

Spinner in android is a view which shows you a drop down menu and lets you select one of the items.

Let us see how to use a spinner in your android program.

<?xml version="1.0" encoding="utf-8"?><LinearLayoutxmlns: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"android:orientation="vertical"app:layout_behavior="@string/appbar_scrolling_view_behavior"tools:context="com.hegdeapps.myapplication.MainActivity"tools:showIn="@layout/activity_main"><TextViewandroid:id="@+id/textView"android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="select currency"/><Spinnerandroid:id="@+id/spinner"android:layout_width="150…

Actionbar and toolbar using support library

Action bar has been our friend since a long time. But it has its own drawbacks. You can not change its color, or size or appearance of its elements.

So came toolbar in android Lollipop. The beauty of this is, you add a toolbar like any other item in the layout xml file, set its color, size, position. Then add a few lines of code to make it an action bar.

So let us dive straight into coding.

I am using support library for toolbar and also appcompat activity. If you do not want to bother about devices with older versions than 5.0, you can straight use toolbar.


You can find toolbar in appcompat option in Android studio design view of your xml file.

So you insert that toolbar in the layout xml file.

<?xml version="1.0" encoding="utf-8"?><LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android"android:orientation="vertical"android:layout_width="match_parent" android:layout_margin="10dp"android:layout_heig…

DatePickers in Android

DatePicker is a view which lets the user select a date showing a calendar or 3 spinners for dd, mm and yy.

Let us see how to use this.
Easy Method: To use a DatePicker you can use DatePickerDialog. This can be created and shown programmatically too.

publicvoidonCreate(Bundle b){/*********/ Button btn =(Button)findViewById(R.id.btn); btn.setOnClickListener(new View.OnClickListener(){@OverridepublicvoidonClick(View v){ showPickerDialog();}});}privatevoidshowPickerDialog(){ DatePickerDialog dtPickerDlg =new DatePickerDialog(this,this, 2017,10,20); dtPickerDialog.show();}

In our xml file, let us have a button and in the onclick listener of the button, let us display the date picker dialog - we call showPickerDialog.

In showPickerDialog,  we are using a random date to initialize.

The first  parameter is the context. Second parameter is the class which implements the interface OnDateSetListener. Next three parameters are year, month (Jan is 0) and …