Thursday, 17 December 2015

How to find, where your database stored in Android Studio


I am going to tell you where you can find Database which is stored in android studio. You often need to see your Database file which is created by you. Also you want to see your data has been updated or inserted or not.

You have to understand run your application in emulator-:

Step 1-: Run your application in emulator.

Step 2-: If your emulator started, Now go to "Tools" -> "Android" -> "DDMS (monitor included)". You can also open the DDMS from:



Step 3-: Select project package name from your emulator and then select package Explorer(you can see in rectangle mark)




Step 4-: You will be able to see internal storage of Emulator.


Step 5-: Expand "Data" Directory you will see one more "Data" directory, again expand data folder.



Step 6-: You can see your project package name inside second data folder. Expand you project package name you will see database folder.



Step 7-: Expand database folder you will see the Database File.




Step 8-: You can pull you database file from that directory in you system.


Step 9-: Open FireFox Browser Type belwo url you will be able to see ADD-ONS SQLite Manager.
https://addons.mozilla.org/en-US/firefox/addon/sqlite-manager/



Step 10-: Click on "+ Add to Firefox" after installation restart Firefox, Now you will be able to see database icon in Firefox. Click on SQLite Manager icon which is mark in circle or you can open "Tools" -> "SQLite Manager"




Step 11-: Now you will be able to SQLite Manager. You can open your database file which has been pull from DDMS.




Get Position when Click on ListView and Click on Button in ListView

I am going to create customized ListView. In each row item put a Button so when user click on button it will show position of the item in ListView. In the same way when user click on ListView it will show position of the item in ListView.

Set the listener on ListView-:

listView.setOnItemClickListener(onItemClickListener);
Define the listener

private AdapterView.OnItemClickListener onItemClickListener = new AdapterView.OnItemClickListener() {

        @Override

        public void onItemClick(AdapterView<?> arg0, View arg1, int position,
                                long arg3) {
            Toast.makeText(MainActivity.this, "This is click=" + position, Toast.LENGTH_LONG).show();
        }

    };

Set the OnClickListener on Button which is entail in ListView Row Item layout-:

eventButton.setOnClickListener(eventButtonClickListener);

Define the OnClickListener :

private OnClickListener eventButtonClickListener = new OnClickListener() {     
     @Override                                                                  
     public void onClick(View v) {                                              
         View parentRow = (View) v.getParent();                                 
         ListView listView = (ListView) parentRow.getParent();                  
         final int position = listView.getPositionForView(parentRow);           
                                                                                
     }                                                                          
 };