Friday 2 September 2016

Android SQLite Database Viewer or Debuging with Stetho

Every Android Developer uses SQLite Database to store data into the Android Application data. But to view the data in SQLite have a lot of options to view.

Today I am going to explain one of the famous Database viewer introduced by the Facebook.
Facebook people have released one SQLite Database viewer called Stetho. By using this Developers can access the SQLite database from the Chrome desktop browser.

Add this line to your build.gradle file:

compile 'com.facebook.stetho:stetho:1.4.2'
 
 And add this line to your Activity/Application Class onCreate() method: 
 
public class MyApplication extends Application {
  public void onCreate() {
    super.onCreate();
    Stetho.initializeWithDefaults(this);
  }
}
Once application Runs in your Emulator/Real Device you can see the database from the Chrome.

Open it from Chrome :

chrome://inspect/#devices 

you can see the below screen:

Step 2:








Source Information from:
https://github.com/facebook/stetho

Thursday 11 February 2016

AlertDialog List Items with onClick and onItemLongClick


                // TODO Auto-generated method stub
                AlertDialog.Builder alertBuilder = new AlertDialog.Builder(
                        ListAlertDailog.this);
                alertBuilder.setIcon(R.drawable.ic_launcher);
                alertBuilder.setTitle("Select Mobile OS:-");
                final ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(
                        ListAlertDailog.this,
                        android.R.layout.select_dialog_item);
                arrayAdapter.add("Android");
                arrayAdapter.add("IOS");
                arrayAdapter.add("Windows");
                arrayAdapter.add("Bada");
                arrayAdapter.add("BlackBerry OS");
                arrayAdapter.add("Symbian OS");

                alertBuilder.setNegativeButton("Cancle",
                        new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog,
                                    int which) {
                                dialog.dismiss();
                            }
                        });

                alertBuilder.setAdapter(arrayAdapter,
                        new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog,
                                    int which) {
                                String strOS = arrayAdapter.getItem(which);
                                Toast.makeText(getApplicationContext(),
                                        "On click selected " + strOS, Toast.LENGTH_SHORT)
                                        .show();
                                dialog.dismiss();
                            }
                        });

                final AlertDialog alertDialog = alertBuilder.create();
                alertDialog.setOnShowListener(new OnShowListener() {

                    @Override
                    public void onShow(DialogInterface dialog) {
                        // TODO Auto-generated method stub
                        ListView listView = alertDialog.getListView();
                        listView.setOnItemLongClickListener(new OnItemLongClickListener() {

                            @Override
                            public boolean onItemLongClick(
                                    AdapterView<?> parent, View view,
                                    int position, long id) {
                                // TODO Auto-generated method stub
                                String strOS = arrayAdapter.getItem(position);
                                Toast.makeText(getApplicationContext(),
                                        "Long Press " + strOS,
                                        Toast.LENGTH_SHORT).show();
                                alertDialog.dismiss();
                                return true;
                            }
                        });
                    }
                });

                alertDialog.show();
           

Monday 4 January 2016

How to compare dates in android or Java (String format dates compare in java)



  Here is the example to compare 2 string format dates :
 
 
 String dateOneStr = "12/02/2016";
        String dateTwoStr = "13/02/2016";
        Date date1,date2;
    DateFormat df = new SimpleDateFormat("dd/MM/yyyy"); 
    try {
     date1 = df.parse(dateOneStr);
     date2 = df.parse(dateTwoStr);
       
        if(date1.after(date2)){
               System.out.println("Date1 is after Date2");
           }

           if(date1.before(date2)){
               System.out.println("Date1 is before Date2");
           }

           if(date1.equals(date2)){
               System.out.println("Date1 is equal Date2");
           }
       
    } catch (ParseException e) {
        e.printStackTrace();
    }

Android SQLite Database Viewer or Debuging with Stetho

Every Android Developer uses SQLite Database to store data into the Android Application data. But to view the data in SQLite have a lot of...