One Layout Class and many fragment layouts in Android Studio

Fragment programming seems to be smart steps towards making worthy applications in Android Studio. In my last experiment, I tried to develop fragments in my app, but I realized that each fragment layout is represented by a Java class which handles the activities. 2017-02-26_001655

How can I use same Java class for different layouts? The first option created an argument constructor for the Java class, but the Fragment sibling Java class doesn’t support thing like that, instead, Android Studio supplies SetArguments and getArguments methods for the purpose.

I have group Main fragment layout carries many buttons for various functions like create,  list, Report fragments respectively. I want to use same Java Class for every fragment including the maingroupFragment.

2017-06-22_084924

The Drawer app code

private void selectItem(int position) {

    mCurrentSelectedPosition = position;
    if (mDrawerListView != null) {
        mDrawerListView.setItemChecked(position, true);
    }
    if (mDrawerLayout != null) {
        mDrawerLayout.closeDrawer(mFragmentContainerView);
    }
    if (mCallbacks != null) {
        mCallbacks.onNavigationDrawerItemSelected(position);
    }
    android.support.v4.app.FragmentManager frg=getFragmentManager();
    switch (position){
        case 0:
            frg.beginTransaction().replace(R.id.FrameContainer, new DashboardFragment()).commit();
            break;
        case 1:
            frg.beginTransaction().replace(R.id.FrameContainer, new LedgerFragment()).commit();
            break;
        case 2:
            frg.beginTransaction().replace(R.id.FrameContainer, new PaymentFragment()).commit();
            break;
        case 3:
            frg.beginTransaction().replace(R.id.FrameContainer, new ReceiptFragment()).commit();
            break;
        case 4:
            frg.beginTransaction().replace(R.id.FrameContainer, new ReportFragment()).commit();
            break;
        case 5:
            Bundle b=new Bundle();
            b.putInt("GroupIndex", R.layout.groupmain_fragment);
            GroupFragment g=new GroupFragment();
            g.setArguments(b);
            frg.beginTransaction().replace(R.id.FrameContainer,g).commit();
            break;
    }
}

The Fragment class

package com.example.developerm.myapplication;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;

/**
* Created by developerM on 14-Jun-2017.
*/
public class GroupFragment extends Fragment {



@Override
public void setArguments(Bundle args) {
super.setArguments(args);
}

public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
// View rootview=inflater.inflate(R.layout.group_registration,container,false);
View rootview=null;
if(getArguments().getInt("GroupIndex")==R.layout.groupmain_fragment){
rootview = inflater.inflate(getArguments().getInt("GroupIndex", 0), container, false);
}
else if(getArguments().getInt("GroupNew")==R.layout.group_registration){

rootview = inflater.inflate(getArguments().getInt("GroupNew", 1), container, false);
}
else if(getArguments().getInt("GroupManage")==R.layout.managegroupsfragment)
{
rootview = inflater.inflate(getArguments().getInt("GroupManage", 2), container, false);
}
else if(getArguments().getInt("GroupAcReports")==R.layout.acreportgroupfragment)
{
rootview = inflater.inflate(getArguments().getInt("GroupAcReports", 3), container, false);
}
else if(getArguments().getInt("GroupList")==R.layout.grouplistfragment)
{
rootview = inflater.inflate(getArguments().getInt("GroupList", 4), container, false);
}

Bundle b=new Bundle();
Button bt;
if(getArguments().getInt("GroupIndex")==R.layout.groupmain_fragment){
bt=(Button) rootview.findViewById(R.id.btn_newGroup);
bt.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Bundle b=new Bundle();
b.putInt("GroupNew", R.layout.group_registration);
GroupFragment g=new GroupFragment();
g.setArguments(b);
android.support.v4.app.FragmentManager frg=getFragmentManager();
frg.beginTransaction().replace(R.id.FrameContainer, g).commit();
}
});
bt=(Button) rootview.findViewById(R.id.btn_findEdit);
bt.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Bundle b=new Bundle();
b.putInt("GroupManage", R.layout.managegroupsfragment);
GroupFragment g=new GroupFragment();
g.setArguments(b);
android.support.v4.app.FragmentManager frg=getFragmentManager();
frg.beginTransaction().replace(R.id.FrameContainer, g).commit();
}
});
bt=(Button) rootview.findViewById(R.id.btn_acReports);
bt.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Bundle b=new Bundle();
b.putInt("GroupAcReports", R.layout.acreportgroupfragment);
GroupFragment g=new GroupFragment();
g.setArguments(b);
android.support.v4.app.FragmentManager frg=getFragmentManager();
frg.beginTransaction().replace(R.id.FrameContainer, g).commit();
}
});
bt=(Button) rootview.findViewById(R.id.btn_groupList);
bt.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Bundle b=new Bundle();
b.putInt("GroupList", R.layout.grouplistfragment);
GroupFragment g=new GroupFragment();
g.setArguments(b);
android.support.v4.app.FragmentManager frg=getFragmentManager();
frg.beginTransaction().replace(R.id.FrameContainer, g).commit();
}
});


}

return rootview;
}
}

The above codes will be explained what you have to do. Use the Argument and getArgument in place.

Expect comments and suggestions

How to make database read/write in SQL

When we have the problem with READ ONLY SQL DATABASE(It can happen while we trying to attach different version database file),  first up all we need to make the security of ldf and mdf file to everyone-Full Control.( if not working,  do the same for folder and drive in which the database file resides. )
And then simply execute the script

USE [master]

Go

Alter database [readonlydb] set READ_WRITE WITH NO_WAIT

GO

Or use the query without the NO_WAIT option.

USE [master]

Go

Alter database [readonlydb] set READ_WRITE

GO

Copying rows from one Access database to Another using Query

In access database, we can copy rows from one table to another using query. How can we transfer rows from one database to another?

Using the in  keyword in Insert statement we can specify an external database path as follows in a access query

insert into Account_Transactions(Date ,Name ,Type ) in ‘D:\Sherpharma\T.mdb’ select  Account_Transactions.Date,Account_Transactions.Name,Account_Transactions.Type from  Account_Transactions

Here we copy the rows from current database to the T.mdb files. We can also use this query in programming as well.

 

How to add font selector property to User-control in VB6

Adding a property to a user control in VB6 requires 4 subroutines to be filled, the Let/Set, Get and property Bags respectively.

Let and get have the variant as return type as an argument, which means any value can be accessed through the property.

Public Property Get Interval() As Variant

Interval = Timer1.Interval

End Property

Public Property Let Interval(ByVal vNewValue As Variant)

Timer1.Interval = vNewValue

PropertyChanged “Interval”

End Property

Suppose you want to change how do you get the Font Dialog within the Property Window. This can be possible with use of stdfont  in place of Variant as follows

Public Property Set Font(ByVal Nfont As StdFont)

Set lbl_Time.Font = Nfont

Refresh

PropertyChanged “Font”

End Property

Public Property Get Font() As StdFont

Set Font = UserControl.lbl_Time.Font

End Property

The complete VB6 Stopwatch Project can be accessible in my GitHub repository