Saturday, 13 December 2014

Stop Refreshing on List View With Check Box / Radio Button

Stop Refreshing on List View With Check Box / Radio Button

Hi!

                 In our Development, Mostly Developers facing one common problem while developing listview with CheckBox / Radio Buttons.

       After you load your data on Listview, when you scroll the listview the selected items will disappear and some items will selected automatically. this problem is because of we are try to figure out the item by position. But when the listview is scrolled up / down the position will be reset.

The solution is we have to take the components tag position by getTag(), and we can identify by this tag position. But should set the Tag before set the value on the Item.

On Business Class

boolean P_is_checked;

i have create a boolean value to carry the state.

On The Adapter Class
{
// radio button on checkedchangelistener
rb_p.setOnCheckedChangeListener(new OnCheckedChangeListener() {

@Override
public void onCheckedChanged(CompoundButton buttonView,
boolean isChecked) {
//  Step - 1 get the tag position while it is checked
int getPosition = (Integer) buttonView.getTag(); 
                               // Step - 2 On The Business Class Object set the boolean value state
A_list.get(getPosition).setP_is_checked(buttonView.isChecked());
}
});
// Step - 3 set the Tag position
rb_p.setTag(position);
//Step - 4 Set the value of the item
rb_p.setChecked(A_list.get(position).P_is_checked);
}

Thats all, no your listview the CheckBox / RadioButton will never check or unchecked automatically while scrolling..,


Enjoy..,

Thank You!

Please Leave Your Comment..,


Have A Happy Day..,

Monday, 1 December 2014

Set Demo Period Expired

Demo Period Expired

Today i am going to show the tips about, how to set the demo period in Android Application?

There are several ways to do it, But very simple and perfect way is to use SharedPreferences,

1) Step

we have to create a SharedPreferences to keep the mandatory details about the application,

2) Step 

To save the current date (Installation Date) on it.

3) Step 

Check the condition for every wakeup of the application for expire period days with the current date,


This is the method to check the validation of 10 Days Demo

private final SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
private final long oneday = 24 * 60 * 60 * 1000;

public void checkExpireDate() throws ParseException {
SharedPreferences preferences = getPreferences(MODE_PRIVATE);
String installDate = preferences.getString("InstallDate", null);
if (installDate == null) {
SharedPreferences.Editor editor = preferences.edit();
Date now = new Date();
String dateString = formatter.format(now);
editor.putString("InstallDate", dateString);
editor.commit();
} else {
Date before = (Date) formatter.parse(installDate);
Date now = new Date();
long diff = now.getTime() - before.getTime();
long days = diff / oneday;
if (days > 10) {
AlertDialog.Builder ad= new AlertDialog.Builder(new ContextThemeWrapper(ReaderB.this, R.style.popup_theme));
ad.setTitle("Your App Is Exceeded the Trial Version");
ad.setMessage("Do You Want To Purchase?..,");
ad.setInverseBackgroundForced(false);
ad.setCancelable(false);
ad.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
// Direct to our site if the application is expired
@Override
public void onClick(DialogInterface dialog, int which) {
Intent fina=new Intent(ReaderB.this,DcsSite.class);
startActivity(fina);
finish();
}
});
ad.setNegativeButton("No",new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
finish();
}
});
ad.show();
}
}
}

Style. xml file for Popup Theme 

 <!-- Application theme. -->
    <style name="AppTheme" parent="AppBaseTheme">
        <!-- All customizations that are NOT specific to a particular API-level can go here. -->
    </style>
    <color name="back_color">#ffffffff</color>

    <style name="popup_theme" parent="@android:style/Theme.Dialog">
        <item name="android:textAppearance">?android:attr/textAppearanceInverse</item>
        <item name="android:windowBackground">@color/back_color</item>
        <item name="android:colorBackground">@color/back_color</item>
    </style>

Thats All..,

Thank You!

Please Leave Your Comment..,


Have A Happy Day..,