编码下一个和后一个按钮

时间:2014-03-25 11:20:08

标签: android sqlite

在此代码中,我通过在点击后退和下一个按钮从本地数据库中检索它来逐个匹配表名来显示问题。最初当我按下下一个按钮它工作正常并正确显示所有问题时,同时按下后退按钮也很好,但是当我按下一个下一个然后再次显示下一个索引而不是前一个索引的问题时。

    public void compareTableName()
    {

        Cursor c=db.getQuestionnum(username,surveyName,selectedQues,tablename);
        if(tablename.equals("email"))
        {
            selectedTableName=tablename;
            Log.e("table",selectedTableName);
            i_email=0;
            if(c.moveToPosition(i_email))
            {
                int index=c.getColumnIndex("question_no");
                Log.e("index",""+index);
                question_no= c.getInt(index);
                Log.e("question_no"," "+question_no);
                next_email++;
                back_email=-1;
                i_email++;
                //counter_email=1;

            }
            Bundle emailBundle=new Bundle();
            emailBundle.putInt("questionnum",question_no);
            emailBundle.putString("username",username);
            emailBundle.putString("surveyname",surveyName);
            emailBundle.putString("quesname",selectedQues);
            EmailFragment emailFrag=new EmailFragment();//create the fragment instance for the top fragment
            emailFrag.setArguments(emailBundle);
            FragmentManager manager=getFragmentManager();//create an instance of fragment manager
            transaction=manager.beginTransaction();
            transaction.add(R.id.MyFrameLayout,emailFrag, "email");
            transaction.commit();
        }
        if(tablename.equals("numerictext"))
        {
            selectedTableName=tablename;
            Log.e("table",selectedTableName);
            i_numeric=0;
            back_numeric=-1;
            //Cursor c=db.getQuestionnum(username,surveyName,selectedQues,tablename);
            if(c.moveToPosition(i_numeric))
            {
                int index=c.getColumnIndex("question_no");
                Log.e("index",""+index);
                question_no= c.getInt(index);
                Log.e("question_no"," "+question_no);
                next_numeric++;
                i_numeric++;
                //counter_numeric=1;

            }
            Bundle numericBundle=new Bundle();
            numericBundle.putInt("questionnum",question_no);
            NumericFragment numericFrag=new NumericFragment();//create the fragment instance for the top fragment
            numericFrag.setArguments(numericBundle);
            FragmentManager manager=getFragmentManager();//create an instance of fragment manager
            transaction=manager.beginTransaction();
            transaction.add(R.id.MyFrameLayout,numericFrag, "numeric");
            transaction.commit();
        }
        else if(tablename.equals("signature"))
        {
            selectedTableName=tablename;
            Toast.makeText(getBaseContext(), "inside else of onclick"+selectedTableName, Toast.LENGTH_SHORT).show();
            Log.e("inside signature text","inside");
            i_signature=0;
            //Cursor c=db.getQuestionnum(username,surveyName,selectedQues,tablename);
            if(c.moveToPosition(i_signature))
            {
                int index=c.getColumnIndex("question_no");
                Log.e("index",""+index);
                question_no= c.getInt(index);
                Log.e("question_no"," "+question_no);
                next_signature++;
                i_signature++;
                //counter_sign=1;

            }

            Bundle signatureBundle=new Bundle();
            signatureBundle.putInt("questionnum",question_no);
            //intent.putExtra("android.intent.extra.INTENT",numericBundle);
            CaptureSignature signatureFrag=new CaptureSignature();
            signatureFrag.setArguments( signatureBundle);
            FragmentManager manager=getFragmentManager();//create an instance of fragment manager
            transaction=manager.beginTransaction();
            transaction.replace(R.id.MyFrameLayout,signatureFrag, "signature");
            //transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
            transaction.commit();

        }
        else if(tablename.equals("information"))
        {
            selectedTableName=tablename;
            Toast.makeText(getBaseContext(), "inside else of onclick"+selectedTableName, Toast.LENGTH_SHORT).show();
            Log.e("inside signature text","inside");
            i_information=0;
            //Cursor c=db.getQuestionnum(username,surveyName,selectedQues,tablename);
            if(c.moveToPosition(i_information))
            {
                int index=c.getColumnIndex("question_no");
                Log.e("index",""+index);
                question_no= c.getInt(index);
                Log.e("question_no"," "+question_no);
                next_info++;
                i_information++;
                //counter_info=1;

            }

            Bundle informationBundle=new Bundle();
            informationBundle.putInt("questionnum",question_no);
            //intent.putExtra("android.intent.extra.INTENT",numericBundle);
            InformationFragment informationFrag=new InformationFragment();
            informationFrag.setArguments(informationBundle);
            FragmentManager manager=getFragmentManager();//create an instance of fragment manager
            transaction=manager.beginTransaction();
            transaction.replace(R.id.MyFrameLayout,informationFrag, "information");
            //transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
            transaction.commit();

        }

    }   


        @SuppressLint("NewApi")
        @Override
        public void onClick(View v) 
        {

            if(v.getId()==R.id.next)
            {
                i++;
                nextButton++;
                backcounter--;
                Log.e("nextbutton",""+nextButton);
                Log.e("value of i",""+i);
                Toast.makeText(this,tablename+i,Toast.LENGTH_LONG).show();
                cursor=db.getAllRecordsTable(username, surveyName, selectedQues);

                counter_info=0;
                counter_numeric=0;
                counter_sign=0;
                counter_email=0;
                if(cursor.moveToPosition(i))
            {
                tablename=cursor.getString(0);
                Log.e("inside click",tablename);
                //Toast.makeText(this,tablename,Toast.LENGTH_LONG).show();
            }


            Cursor c=db.getQuestionnum(username,surveyName,selectedQues,tablename); 
            if(tablename.equals("numerictext"))
                {

                    selectedTableName=tablename;
                    tableLastClicked=selectedTableName;
                    Toast.makeText(getBaseContext(), "inside else of onclick"+selectedTableName, Toast.LENGTH_SHORT).show();
                    Log.e("inside numerci text","inside");
                    Log.e("value","before"+i_numeric);
                    counter_info=1;
                    //next_numeric=0;
                    //next_numeric++;
                    //if(backcounter!=1)
                    //{
                        if(i_numeric==-1)
                        i_numeric=0;

                        if(tableBackClicked.equals("numerictext"))
                        {
                                i_numeric++;
                                tableBackClicked="";
                        }

                    /*else
                        i_numeric++;
                    }
                    else
                    {
                        i_numeric=next_numeric;
                    }
                    //counter=0;

                    /*if(counter_numeric!=1)
                    {
                        if(i_numeric>=1)
                        {
                            i_numeric++;
                        }
                    }
                    if(counter_numeric==1)
                    {
                        i_numeric++;
                        counter_numeric=0;
                    }*/

                    if(c.moveToPosition(i_numeric))
                    {
                        //if(i_numeric==0)
                        i_numeric++;
                        int index=c.getColumnIndex("question_no");
                        Log.e("index",""+index);
                        question_no= c.getInt(index);
                        Log.e("question_no"," "+question_no);
                        Toast.makeText(this,"question no is"+question_no,Toast.LENGTH_SHORT);

                    }
                    Log.e("value numeric","after"+i_numeric);

                    Bundle numericBundle=new Bundle();
                    numericBundle.putString("username",username);
                    numericBundle.putString("surveyname",surveyName);
                    numericBundle.putString("quesname",selectedQues);
                    numericBundle.putInt("questionnum",question_no);
                    //intent.putExtra("android.intent.extra.INTENT",numericBundle);
                    NumericFragment numericFrag=new NumericFragment();
                    numericFrag.setArguments( numericBundle);
                    FragmentManager manager=getFragmentManager();//create an instance of fragment manager
                    transaction=manager.beginTransaction();
                    transaction.replace(R.id.MyFrameLayout,numericFrag, "numeric");
                    //transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
                    transaction.commit();
               }
                else if(tablename.equals("signature"))
                {
                    selectedTableName=tablename;
                    tableLastClicked=selectedTableName;
                    Toast.makeText(getBaseContext(), "last clicked"+selectedTableName, Toast.LENGTH_SHORT).show();
                    Log.e("inside signature text","inside");
                    Log.e("value sign","before"+i_signature);
                    //back_signature=-1;
                    //if(backcounter!=1)
                    //{
                        if(i_signature==-1)
                            i_signature=0;

                        if(tableBackClicked.equals("signature"))
                        {
                            i_signature++;
                            tableBackClicked="";
                        }
                        /*else
                            next_signature++;
                    }

                    else
                    {
                        i_signature=next_signature;
                    }
                    //counter=0;
                    /*if(counter_sign!=1)
                    {
                        if(i_signature>=1)
                        {
                            i_signature++;
                        }
                    }
                    if(counter_sign==1)
                    {
                        i_signature++;
                        counter_sign=0;
                    }*/
                    Log.e("value sign","before"+i_signature);
                    //Cursor c=db.getQuestionnum(username,surveyName,selectedQues,tablename);
                    //counter_sign=1;
                    if(c.moveToPosition(i_signature))
                    {
                        //if(i_signature==0)
                            i_signature++;
                        int index=c.getColumnIndex("question_no");
                        Log.e("index",""+index);
                        question_no= c.getInt(index);
                        Log.e("question_no"," "+question_no);

                    }

                    Bundle signatureBundle=new Bundle();
                    signatureBundle.putInt("questionnum",question_no);
                    signatureBundle.putString("username",username);
                    signatureBundle.putString("surveyname",surveyName);
                    signatureBundle.putString("quesname",selectedQues);
                    //intent.putExtra("android.intent.extra.INTENT",numericBundle);
                    CaptureSignature signatureFrag=new CaptureSignature();
                    signatureFrag.setArguments( signatureBundle);
                    FragmentManager manager=getFragmentManager();//create an instance of fragment manager
                    transaction=manager.beginTransaction();
                    transaction.replace(R.id.MyFrameLayout,signatureFrag, "signature");
                    //transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
                    transaction.commit();

        }
        else if(tablename.equals("information"))
        {
            selectedTableName=tablename;
            tableLastClicked=selectedTableName;
            Toast.makeText(getBaseContext(), " last click"+tableLastClicked, Toast.LENGTH_SHORT).show();
            Log.e("inside information text","inside");
            Log.e("i_information","before"+i_information);
            Log.e("value info","before"+i_information);
            //counter_info=1;
            //Log.e("backcounter",""+backcounter);
            //next_info++;
            //back_info=-1;
            //if(backcounter!=1)
            //{
                if(i_information==-1)
                    i_information=0;

                if(tableBackClicked.equals("information"))
                {
                    i_information++;
                    tableBackClicked="";
                }
                /*else
                    i_information++;
            }
            else
            {
                i_information=next_info;
            }



            /*if(counter_info!=1)
            {
                if(i_information>1)
                {
                    i_information++;
                }
            }
            if(counter_info==1)
            {
                i_information++;
                counter_info=0;
            }*/

            //db.open();
            //Cursor c=db.getQuestionnum(username,surveyName,selectedQues,tablename);
            if(c.moveToPosition(i_information))
            {
                int index=c.getColumnIndex("question_no");
                Log.e("index",""+index);
                question_no= c.getInt(index);
                Log.e("question_no"," "+question_no);
                //if(i_information==0)
                    i_information++;

            }
            Log.e("value info","after"+i_information);
            Bundle informationBundle=new Bundle();
            informationBundle.putInt("questionnum",question_no);
            informationBundle.putString("username",username);
            informationBundle.putString("surveyname",surveyName);
            informationBundle.putString("quesname",selectedQues);
            InformationFragment informationFrag=new InformationFragment();
            informationFrag.setArguments(informationBundle);
            FragmentManager manager=getFragmentManager();//create an instance of fragment manager
            transaction=manager.beginTransaction();
            transaction.replace(R.id.MyFrameLayout,informationFrag, "information");
            //transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
            transaction.commit();

        }
        else if(tablename.equals("email"))
        {
            selectedTableName=tablename;
            tableLastClicked=selectedTableName;
            Log.e("table",tableLastClicked);
            Log.e("value email","before"+i_email);
            /*if(backn==1)
            {
                i_email++;
            }*/
            //e=-1;
            /*back_email=-1;*/
            next_email=0;
            next_email++;
            //Log.e("e",""+e);
            //Log.e("counter inside email",""+counter);
            /*if(counter!=1)
            {
                Log.e("incounter","");*/
                if(i_email==-1)
                {
                    i_email=0;
                }

                if(tableBackClicked.equals("email"))
                {
                    i_email++;
                    tableBackClicked="";
                }


                /*else
                {
                    Log.e("else","");
                    i_email++;
                }
            }
            /*if(counter==1)
            {
                i_email=next_email1;
            }*/
            //Log.e("e1",""+e1);
            /*if(e1!=-1)
            {
                i_email++;
            }*/
            //counter=0;
            /*if(counter_email!=1)
            {
                if(i_email>1)
                {
                    i_email++;
                }
            }*/
            //counter_email=1;
            /*if(counter_email==1||i_email==2)
            {
                i_email++;
            }*/

            //db.open();
            //Cursor c=db.getQuestionnum(username,surveyName,selectedQues,tablename);

            if(c.moveToPosition(i_email))
            {
                //if(i_email==0)
                i_email++;
                Log.e("inside","email table");
                int index=c.getColumnIndex("question_no");
                Log.e("index",""+index);
                question_no= c.getInt(index);
                Log.e("question_no"," "+question_no);


            }
            Log.e("value email","after"+i_email);
            Bundle emailBundle=new Bundle();
            emailBundle.putInt("questionnum",question_no);
            emailBundle.putString("username",username);
            emailBundle.putString("surveyname",surveyName);
            emailBundle.putString("quesname",selectedQues);
            EmailFragment emailFrag=new EmailFragment();//create the fragment instance for the top fragment
            emailFrag.setArguments(emailBundle);
            FragmentManager manager=getFragmentManager();//create an instance of fragment manager
            transaction=manager.beginTransaction();
            transaction.replace(R.id.MyFrameLayout,emailFrag, "email");
            transaction.commit();
        }
                c.close();
}

        else
        {
            i--;
            backcounter++;
            nextButton--;
            Log.e("backcounter",""+backcounter);

            Log.e("value of i",""+i);
            Toast.makeText(this,""+i,Toast.LENGTH_LONG).show();
            cursor=db.getAllRecordsTable(username, surveyName, selectedQues);
        if(cursor.moveToPosition(i))
        {
            tablename=cursor.getString(0);
            Log.e("inside click",tablename);
            Toast.makeText(this,tablename,Toast.LENGTH_LONG).show();
        }


        Cursor c=db.getQuestionnum(username,surveyName,selectedQues,tablename); 
        Toast.makeText(this,"value of curosr"+c.getCount(),Toast.LENGTH_SHORT).show();
        if(tablename.equals("numerictext"))
            {

                selectedTableName=tablename;
                Toast.makeText(getBaseContext(), "inside else of onclick"+selectedTableName, Toast.LENGTH_SHORT).show();
                Log.e("inside numerci text","inside");
                Toast.makeText(this,"inside numeric text",Toast.LENGTH_SHORT).show();
                Log.e("value i","before"+i_numeric);
                //Log.e("back numeric",""+back_numeric);


                /*if(counter_numeric!=1)
                {
                    back_numeric++;
                }
                if(back_numeric==0)
                {
                    i_numeric=next_numeric;
                }
                else*/
                Log.e("table last clicked",tableLastClicked);
                if(tableLastClicked.equals("numerictext"))
                {
                    i_numeric=i_numeric-2;
                    tableLastClicked="";
                }
                else
                    i_numeric--;
                back_numeric=0;

                //next_numeric--;
                /*if(counter_numeric!=0)
                {
                    i_numeric--;
                }*/
                Log.e("value i","after"+i_numeric);
                if(c.moveToPosition(i_numeric))
                {
                    Toast.makeText(this,"inside numeric text"+i_numeric,Toast.LENGTH_SHORT).show();
                    int index=c.getColumnIndex("question_no");
                    Log.e("index",""+index);
                    question_no= c.getInt(index);
                    Log.e("question_no"," "+question_no);
                    //counter_numeric++;
                    //Log.e("count","before"+counter_numeric);
                }
                Bundle numericBundle=new Bundle();
                numericBundle.putString("username",username);
                numericBundle.putString("surveyname",surveyName);
                numericBundle.putString("quesname",selectedQues);
                numericBundle.putInt("questionnum",question_no);
                //intent.putExtra("android.intent.extra.INTENT",numericBundle);
                NumericFragment numericFrag=new NumericFragment();
                numericFrag.setArguments( numericBundle);
                FragmentManager manager=getFragmentManager();//create an instance of fragment manager
                transaction=manager.beginTransaction();
                transaction.replace(R.id.MyFrameLayout,numericFrag, "numeric");
                //transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
                transaction.commit();
           }
            else if(tablename.equals("signature"))
            {
                selectedTableName=tablename;
                Toast.makeText(getBaseContext(), "inside else of onclick"+selectedTableName, Toast.LENGTH_SHORT).show();
                Log.e("inside signature text","inside");

                Log.e("table last clicked",tableLastClicked);
                if(tableLastClicked.equals("signature"))
                {
                    i_signature=i_signature-2;
                    tableLastClicked="";
                }
                else
                    i_signature--;
                back_signature=0;

                //Cursor c=db.getQuestionnum(username,surveyName,selectedQues,tablename);
                Log.e("value i","before"+i_signature);
                /*if(counter_sign!=0)
                {
                    i_signature--;
                }*/
                /*if(counter_sign!=1)
                    back_signature++;
                if(back_signature==0)
                {
                    i_signature=next_signature;
                }
                else
                    i_signature--;

                next_sign=i_signature;*/
                Log.e("value i","after"+i_signature);
                if(c.moveToPosition(i_signature))
                {

                    Toast.makeText(this,"inside signature"+i_signature,Toast.LENGTH_SHORT).show();
                    int index=c.getColumnIndex("question_no");
                    Log.e("index",""+index);
                    question_no= c.getInt(index);
                    Log.e("question_no"," "+question_no);
                    //counter_sign++;
                    Log.e("count","sign"+counter_sign);

                }

                Bundle signatureBundle=new Bundle();
                signatureBundle.putInt("questionnum",question_no);
                signatureBundle.putString("username",username);
                signatureBundle.putString("surveyname",surveyName);
                signatureBundle.putString("quesname",selectedQues);
                //intent.putExtra("android.intent.extra.INTENT",numericBundle);
                CaptureSignature signatureFrag=new CaptureSignature();
                signatureFrag.setArguments( signatureBundle);
                FragmentManager manager=getFragmentManager();//create an instance of fragment manager
                transaction=manager.beginTransaction();
                transaction.replace(R.id.MyFrameLayout,signatureFrag, "signature");
                //transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
                transaction.commit();

    }
    else if(tablename.equals("information"))
    {
        selectedTableName=tablename;
        tableBackClicked=selectedTableName;
        Toast.makeText(getBaseContext(), "inside else of onclick"+selectedTableName, Toast.LENGTH_SHORT).show();
        Log.e("inside info text","inside");
        Log.e("value i","before"+i_information);
        //if(counter_info!=0)
        Log.e("table last clicked",tableLastClicked);
        if(tableLastClicked.equals("information"))
        {
            i_information=i_information-2;
            tableLastClicked="";
        }
        else
            i_information--;
        back_info=0;


        //db.open();
        //Cursor c=db.getQuestionnum(username,surveyName,selectedQues,tablename);
        /*if(counter_info!=1)
        {
            back_info++;
        }
        if(back_info==0)
        {
            i_information=next_info;
        }
        else
            i_information--;
        next_info--;
        Log.e("next_info",""+next_info);*/

        Log.e("value i","after"+i_information);
        /*Log.e("valuebackinfo",""+back_info);

        next_information=i_information;*/

        if(c.moveToPosition(i_information))
        {

            Toast.makeText(this,"inside information"+i_information,Toast.LENGTH_SHORT).show();
            int index=c.getColumnIndex("question_no");
            Log.e("index",""+index);
            question_no= c.getInt(index);
            Log.e("question_no"," "+question_no);

        }

        Bundle informationBundle=new Bundle();
        informationBundle.putInt("questionnum",question_no);
        informationBundle.putString("username",username);
        informationBundle.putString("surveyname",surveyName);
        informationBundle.putString("quesname",selectedQues);
        //intent.putExtra("android.intent.extra.INTENT",numericBundle);
        InformationFragment informationFrag=new InformationFragment();
        informationFrag.setArguments(informationBundle);
        FragmentManager manager=getFragmentManager();//create an instance of fragment manager
        transaction=manager.beginTransaction();
        transaction.replace(R.id.MyFrameLayout,informationFrag, "information");
        //transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
        transaction.commit();

    }
    else if(tablename.equals("email"))
    {
        selectedTableName=tablename;
        tableBackClicked=selectedTableName;
        Log.e("table",selectedTableName);
        //db.open();
        //Cursor c=db.getQuestionnum(username,surveyName,selectedQues,tablename);
        Log.e("value of curosr",""+c.getCount());
        Log.e("value i","before"+i_email);
        //Log.e("e back",""+e);
        //e1=-1;
        //Log.e("e1",""+e);
        //e1++;
        //Log.e("e1",""+e);
        //backn=1;
        /*e++;
        if(e==0)
        {
            i_email--;
        }
        if(counter_email!=0)
            i_email--;*/
        Log.e("before",""+i_email);

        /*if(counter_email!=1)
        {
            back_email++;
        }
        if(back_email==0)
        {
            i_email=next_email;
        }
        else*/
        //back_email++;
        //Log.e("back_email",""+back_email);
        Log.e("table last clicked",tableLastClicked);
        if(tableLastClicked.equals("email"))
        {
            i_email=i_email-2;
            tableLastClicked="";
        }
        else
            i_email--;
        back_email=0;

        //Log.e("after",""+next_email);
        Log.e("value i","after"+i_email);
        if(c.moveToPosition(i_email))
        {
            Log.e("inside","email table");
            Toast.makeText(this,"inside email"+i_email,Toast.LENGTH_SHORT).show();
            int index=c.getColumnIndex("question_no");
            Log.e("index",""+index);
            question_no= c.getInt(index);
            Log.e("question_no of email"," "+question_no);
            //counter_email++;
            //Log.e("counter","email"+counter_email);

        }
        Bundle emailBundle=new Bundle();
        emailBundle.putInt("questionnum",question_no);
        emailBundle.putString("username",username);
        emailBundle.putString("surveyname",surveyName);
        emailBundle.putString("quesname",selectedQues);
        EmailFragment emailFrag=new EmailFragment();//create the fragment instance for the top fragment
        emailFrag.setArguments(emailBundle);
        FragmentManager manager=getFragmentManager();//create an instance of fragment manager
        transaction=manager.beginTransaction();
        transaction.replace(R.id.MyFrameLayout,emailFrag, "email");
        transaction.commit();
    }
    c.close();
 }

}

}

2 个答案:

答案 0 :(得分:0)

实施这个

@Override
    public void onBackPressed() {

        if (currentFragment instanceof IBackListener) {
            if (((IBackListener) currentFragment).onBackPressed())
                return;
        }

        FragmentManager manager = getSupportFragmentManager();

        if (manager.getBackStackEntryCount() > 1) {
            resetActionBar();
            manager.popBackStack();
            return;
        }

        if (getIntent().getBooleanExtra(SHOW_TOAST_ON_BACK, true)) {
            if (lastBackPressed + 3000 > System.currentTimeMillis())
                finish();
            else {
                if (!mNavLayout.isOpen() && slidingPaneEnabled)
                    mNavLayout.openPane();
                lastBackPressed = System.currentTimeMillis();
                Toast.makeText(this, "Press back again to exit", Toast.LENGTH_SHORT).show();
            }
        } else {
            if (!mNavLayout.isOpen() && slidingPaneEnabled)
                mNavLayout.openPane();
            else
                finish();
        }
    }

答案 1 :(得分:0)

这是我的问题的解决方案。

public void getTableName()
    {
        cursor=db.getAllRecordsTable(username, surveyName, selectedQues);
        lastques=cursor.getCount();
        if(cursor.moveToPosition(i))
        {
            tablename=cursor.getString(0);
        }
        cursor.close();

    }
    @SuppressLint("NewApi")
        public void compareTableName()
        {

            Cursor c=db.getQuestionnum(username,surveyName,selectedQues);
            j=0;
            if(tablename.equals("email"))
            {
                selectedTableName=tablename;
                if(c.moveToPosition(j))
                {
                    int index=c.getColumnIndex("question_no");
                    question_no= c.getInt(index);
                    db.insertQuestion(question_no);
                }
                Bundle emailBundle=new Bundle();
                emailBundle.putInt("questionnum",question_no);
                emailBundle.putString("username",username);
                emailBundle.putString("surveyname",surveyName);
                emailBundle.putString("quesname",selectedQues);
                EmailFragment emailFrag=new EmailFragment();//create the fragment instance for the top fragment
                emailFrag.setArguments(emailBundle);
                FragmentManager manager=getFragmentManager();//create an instance of fragment manager
                transaction=manager.beginTransaction();
                transaction.add(R.id.MyFrameLayout,emailFrag, "email");
                transaction.commit();
            }
            if(tablename.equals("numerictext"))
            {
                selectedTableName=tablename;
                if(c.moveToPosition(j))
                {
                    int index=c.getColumnIndex("question_no");
                    question_no= c.getInt(index);
                    db.insertQuestion(question_no);
                }
                Bundle numericBundle=new Bundle();
                numericBundle.putInt("questionnum",question_no);
                numericBundle.putString("username",username);
                numericBundle.putString("surveyname",surveyName);
                numericBundle.putString("quesname",selectedQues);
                NumericFragment numericFrag=new NumericFragment();//create the fragment instance for the top fragment
                numericFrag.setArguments(numericBundle);
                FragmentManager manager=getFragmentManager();//create an instance of fragment manager
                transaction=manager.beginTransaction();
                transaction.add(R.id.MyFrameLayout,numericFrag, "numeric");
                transaction.commit();
            }
            else if(tablename.equals("signature"))
            {
                selectedTableName=tablename;
                if(c.moveToPosition(j))
                {
                    int index=c.getColumnIndex("question_no");
                    question_no= c.getInt(index);
                    db.insertQuestion(question_no);
                }

                Bundle signatureBundle=new Bundle();
                signatureBundle.putInt("questionnum",question_no);
                signatureBundle.putString("username",username);
                signatureBundle.putString("surveyname",surveyName);
                signatureBundle.putString("quesname",selectedQues);
                CaptureSignature signatureFrag=new CaptureSignature();
                signatureFrag.setArguments( signatureBundle);
                FragmentManager manager=getFragmentManager();//create an instance of fragment manager
                transaction=manager.beginTransaction();
                transaction.add(R.id.MyFrameLayout,signatureFrag, "signature");
                //transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
                transaction.commit();

            }
            else if(tablename.equals("information"))
            {
                selectedTableName=tablename;
                if(c.moveToPosition(j))
                {
                    int index=c.getColumnIndex("question_no");
                    question_no= c.getInt(index);
                    db.insertQuestion(question_no);
                }

                Bundle informationBundle=new Bundle();
                informationBundle.putInt("questionnum",question_no);
                informationBundle.putString("username",username);
                informationBundle.putString("surveyname",surveyName);
                informationBundle.putString("quesname",selectedQues);
                InformationFragment informationFrag=new InformationFragment();
                informationFrag.setArguments(informationBundle);
                FragmentManager manager=getFragmentManager();//create an instance of fragment manager
                transaction=manager.beginTransaction();
                transaction.add(R.id.MyFrameLayout,informationFrag, "information");
                transaction.commit();

            }
            else if(tablename.equals("signleselect"))
            {
                selectedTableName=tablename;
                if(c.moveToPosition(j))
                {
                    int index=c.getColumnIndex("question_no");
                    question_no= c.getInt(index);
                    db.insertQuestion(question_no);
                }

                Bundle signleSelectBundle=new Bundle();
                signleSelectBundle.putInt("questionnum",question_no);
                signleSelectBundle.putString("username",username);
                signleSelectBundle.putString("surveyname",surveyName);
                signleSelectBundle.putString("quesname",selectedQues);
                Single_Select singleSelectFrag=new Single_Select();
                singleSelectFrag.setArguments(signleSelectBundle);
                FragmentManager manager=getFragmentManager();//create an instance of fragment manager
                transaction=manager.beginTransaction();
                transaction.add(R.id.MyFrameLayout, singleSelectFrag, "singleselect");
                transaction.commit();

            }
            c.close();

        }   
    @SuppressLint("NewApi")
    @Override
    public void onClick(View v) 
    {

                if(v.getId()==R.id.next)
                {
                    i++;
                    Toast.makeText(this,tablename+i,Toast.LENGTH_LONG).show();
                    cursor=db.getAllRecordsTable(username, surveyName, selectedQues);
                    if(cursor.moveToPosition(i))
                    {
                        tablename=cursor.getString(0);
                        Log.e("inside click",tablename);
                    }


                Cursor c=db.getQuestionnum(username,surveyName,selectedQues);   
                if(valueQues!=0)
                {
                    db.insertQuestion(valueQues);
                    Log.e("lastquestion_no"," "+question_no);
                }
                valueQues=0;
                j++;
                if(tablename.equals("numerictext"))
                    {

                        selectedTableName=tablename;
                        if(c.moveToPosition(j))
                        {
                            int index=c.getColumnIndex("question_no");
                            Log.e("index",""+index);
                            question_no= c.getInt(index);
                            db.insertQuestion(question_no);
                        }

                        Bundle numericBundle=new Bundle();
                        numericBundle.putString("username",username);
                        numericBundle.putString("surveyname",surveyName);
                        numericBundle.putString("quesname",selectedQues);
                        numericBundle.putInt("questionnum",question_no);
                        NumericFragment numericFrag=new NumericFragment();
                        numericFrag.setArguments( numericBundle);
                        FragmentManager manager=getFragmentManager();//create an instance of fragment manager
                        transaction=manager.beginTransaction();
                        transaction.replace(R.id.MyFrameLayout,numericFrag, "numeric");
                        transaction.commit();
                   }
                    else if(tablename.equals("signature"))
                    {
                        selectedTableName=tablename;
                        if(c.moveToPosition(j))
                        {
                            int index=c.getColumnIndex("question_no");
                            question_no= c.getInt(index);
                            db.insertQuestion(question_no);
                        }

                        Bundle signatureBundle=new Bundle();
                        signatureBundle.putInt("questionnum",question_no);
                        signatureBundle.putString("username",username);
                        signatureBundle.putString("surveyname",surveyName);
                        signatureBundle.putString("quesname",selectedQues);
                        CaptureSignature signatureFrag=new CaptureSignature();
                        signatureFrag.setArguments( signatureBundle);
                        FragmentManager manager=getFragmentManager();//create an instance of fragment manager
                        transaction=manager.beginTransaction();
                        transaction.replace(R.id.MyFrameLayout,signatureFrag, "signature");
                        transaction.commit();

            }
            else if(tablename.equals("information"))
            {
                selectedTableName=tablename;
                if(c.moveToPosition(j))
                {
                    int index=c.getColumnIndex("question_no");
                    Log.e("index",""+index);
                    question_no= c.getInt(index);
                    db.insertQuestion(question_no);

                }
                Log.e("value info","after"+i_information);
                Bundle informationBundle=new Bundle();
                informationBundle.putInt("questionnum",question_no);
                informationBundle.putString("username",username);
                informationBundle.putString("surveyname",surveyName);
                informationBundle.putString("quesname",selectedQues);
                //intent.putExtra("android.intent.extra.INTENT",numericBundle);
                InformationFragment informationFrag=new InformationFragment();
                informationFrag.setArguments(informationBundle);
                FragmentManager manager=getFragmentManager();//create an instance of fragment manager
                transaction=manager.beginTransaction();
                transaction.replace(R.id.MyFrameLayout,informationFrag, "information");
                transaction.commit();
              }
            else if(tablename.equals("email"))
            {
                selectedTableName=tablename;
                if(c.moveToPosition(j))
                {
                    int index=c.getColumnIndex("question_no");
                    question_no= c.getInt(index);
                    db.insertQuestion(question_no);
                }
                Log.e("value email","after"+i_email);
                Bundle emailBundle=new Bundle();
                emailBundle.putInt("questionnum",question_no);
                emailBundle.putString("username",username);
                emailBundle.putString("surveyname",surveyName);
                emailBundle.putString("quesname",selectedQues);
                EmailFragment emailFrag=new EmailFragment();//create the fragment instance for the top fragment
                emailFrag.setArguments(emailBundle);
                FragmentManager manager=getFragmentManager();//create an instance of fragment manager
                transaction=manager.beginTransaction();
                transaction.replace(R.id.MyFrameLayout,emailFrag, "email");
                transaction.commit();
            }
            else if(tablename.equals("signleselect"))
            {
                selectedTableName=tablename;
                if(c.moveToPosition(j))
                {
                    int index=c.getColumnIndex("question_no");
                    question_no= c.getInt(index);
                    db.insertQuestion(question_no);
                }

                Bundle signleSelectBundle=new Bundle();
                signleSelectBundle.putInt("questionnum",question_no);
                signleSelectBundle.putString("username",username);
                signleSelectBundle.putString("surveyname",surveyName);
                signleSelectBundle.putString("quesname",selectedQues);
                Single_Select singleSelectFrag=new Single_Select();
                singleSelectFrag.setArguments(signleSelectBundle);
                FragmentManager manager=getFragmentManager();//create an instance of fragment manager
                transaction=manager.beginTransaction();
                transaction.replace(R.id.MyFrameLayout, singleSelectFrag, "singleselect");
                transaction.commit();

            }


            c.close();
            cursor.close();
    }

            else
            {
                i--;
                cursor=db.getAllRecordsTable(username, surveyName, selectedQues);
            if(cursor.moveToPosition(i))
            {
                tablename=cursor.getString(0);
            }
            db.deletequestion(question_no);
            Cursor c=db.getQuestion();
            int pos=c.getCount();
            pos--;
            j--;
            if(tablename.equals("numerictext"))
            {
                selectedTableName=tablename;
                if(c.moveToPosition(pos))
                {
                    int index=c.getColumnIndex("question_no");
                    question_no= c.getInt(index);
                    db.deletequestion(question_no);
                }
                Bundle numericBundle=new Bundle();
                numericBundle.putString("username",username);
                numericBundle.putString("surveyname",surveyName);
                numericBundle.putString("quesname",selectedQues);
                numericBundle.putInt("questionnum",question_no);
                NumericFragment numericFrag=new NumericFragment();
                numericFrag.setArguments( numericBundle);
                FragmentManager manager=getFragmentManager();//create an instance of fragment manager
                transaction=manager.beginTransaction();
                transaction.replace(R.id.MyFrameLayout,numericFrag, "numeric");
                transaction.commit();
               }
                else if(tablename.equals("signature"))
                {
                    selectedTableName=tablename;
                    if(c.moveToPosition(pos))
                    {
                        int index=c.getColumnIndex("question_no");
                        question_no= c.getInt(index);
                        db.deletequestion(question_no);

                    }

                    Bundle signatureBundle=new Bundle();
                    signatureBundle.putInt("questionnum",question_no);
                    signatureBundle.putString("username",username);
                    signatureBundle.putString("surveyname",surveyName);
                    signatureBundle.putString("quesname",selectedQues);
                    CaptureSignature signatureFrag=new CaptureSignature();
                    signatureFrag.setArguments( signatureBundle);
                    FragmentManager manager=getFragmentManager();//create an instance of fragment manager
                    transaction=manager.beginTransaction();
                    transaction.replace(R.id.MyFrameLayout,signatureFrag, "signature");
                    transaction.commit();

        }
        else if(tablename.equals("information"))
        {
            selectedTableName=tablename;
            if(c.moveToPosition(pos))
            {
                int index=c.getColumnIndex("question_no");
                question_no= c.getInt(index);
                db.deletequestion(question_no);

            }

            Bundle informationBundle=new Bundle();
            informationBundle.putInt("questionnum",question_no);
            informationBundle.putString("username",username);
            informationBundle.putString("surveyname",surveyName);
            informationBundle.putString("quesname",selectedQues);
            InformationFragment informationFrag=new InformationFragment();
            informationFrag.setArguments(informationBundle);
            FragmentManager manager=getFragmentManager();//create an instance of fragment manager
            transaction=manager.beginTransaction();
            transaction.replace(R.id.MyFrameLayout,informationFrag, "information");
            //transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
            transaction.commit();

        }
        else if(tablename.equals("email"))
        {
            selectedTableName=tablename;
            if(c.moveToPosition(pos))
            {
                int index=c.getColumnIndex("question_no");
                question_no= c.getInt(index);
                db.deletequestion(question_no);
            }
            Bundle emailBundle=new Bundle();
            emailBundle.putInt("questionnum",question_no);
            emailBundle.putString("username",username);
            emailBundle.putString("surveyname",surveyName);
            emailBundle.putString("quesname",selectedQues);
            EmailFragment emailFrag=new EmailFragment();//create the fragment instance for the top fragment
            emailFrag.setArguments(emailBundle);
            FragmentManager manager=getFragmentManager();//create an instance of fragment manager
            transaction=manager.beginTransaction();
            transaction.replace(R.id.MyFrameLayout,emailFrag, "email");
            transaction.commit();
        }
        else if(tablename.equals("signleselect"))
        {
            selectedTableName=tablename;
            if(c.moveToPosition(pos))
            {
                int index=c.getColumnIndex("question_no");
                question_no= c.getInt(index);
                db.insertQuestion(question_no);
            }

            Bundle signleSelectBundle=new Bundle();
            signleSelectBundle.putInt("questionnum",question_no);
            signleSelectBundle.putString("username",username);
            signleSelectBundle.putString("surveyname",surveyName);
            signleSelectBundle.putString("quesname",selectedQues);
            Single_Select singleSelectFrag=new Single_Select();
            singleSelectFrag.setArguments(signleSelectBundle);
            FragmentManager manager=getFragmentManager();//create an instance of fragment manager
            transaction=manager.beginTransaction();
            transaction.replace(R.id.MyFrameLayout, singleSelectFrag, "singleselect");
            transaction.commit();

        }
        c.close();
        valueQues=question_no;
     }

    }