if-else if语句在android中无法正常工作

时间:2013-07-19 10:05:44

标签: android android-2.3-gingerbread

我的问题是,当我在if条件(pro.getSelectedItemPosition()!=0 && allmemb.getSelectedItemPosition()!=0)中使用多个语句时,会检查它,但如果我使用(pro.getSelectedItemPosition()!=0)之类的单一语句,则不会检查条件。

String where = null;

    if(pro.getSelectedItemPosition()!=0 && allmemb.getSelectedItemPosition()!=0)
    {
         where="PROJECT='"+pro.getSelectedItemPosition()+"' and ASSIGNED_BY='"+allmemb.getSelectedItemPosition()+"'";
    }

    else if(pro.getSelectedItemPosition()!=0 && allmod.getSelectedItemPosition()!=0)
    {
        where="PROJECT='"+pro.getSelectedItemPosition()+"' and MODULE='"+allmod.getSelectedItem()+"'";
    }
    else if(pro.getSelectedItemPosition()!=0 && allprio.getSelectedItemPosition()!=0)
    {
        where="PROJECT='"+pro.getSelectedItemPosition()+"' and PRIORITY='"+allprio.getSelectedItem()+"'";
    }

    else if(pro.getSelectedItemPosition()!=0 && date.getTextSize()!=0)
    {
        where="PROJECT='"+pro.getSelectedItemPosition()+"' and T_DATE='"+date.getText().toString()+"'";
    }
    else if(allmemb.getSelectedItemPosition()!=0 && allmod.getSelectedItemPosition()!=0)
    {
        where="ASSIGNED_BY='"+allmemb.getSelectedItemPosition()+"' and MODULE='"+allmod.getSelectedItem()+"'";
    }
    else if(allmemb.getSelectedItemPosition()!=0 && allprio.getSelectedItemPosition()!=0)
    {
        where="ASSIGNED_BY='"+allmemb.getSelectedItemPosition()+"' and PRIORITY='"+allprio.getSelectedItem()+"'";
    }
    else if(allmemb.getSelectedItemPosition()!=0 && date.getTextSize()!=0)
    {
        where="ASSIGNED_BY='"+allmemb.getSelectedItemPosition()+"' and T_DATE='"+date.getText().toString()+"'";
    }
    else if(allmod.getSelectedItemPosition()!=0 && allprio.getSelectedItemPosition()!=0)
    {
        where="MODULE='"+allmod.getSelectedItem()+"' and PRIORITY='"+allprio.getSelectedItem()+"'";
    }
    else if(allmod.getSelectedItemPosition()!=0 && date.getTextSize()!=0)
    {
        where="MODULE='"+allmod.getSelectedItem()+"' and T_DATE='"+date.getText().toString()+"'";
    }
    else if(allprio.getSelectedItemPosition()!=0 && date.getTextSize()!=0)
    {
        where="PRIORITY='"+allprio.getSelectedItem()+"' and T_DATE='"+date.getText().toString()+"'";
    }
    else if(date.getTextSize()!=0 && date1.getTextSize()!=0)
    {
        where="T_DATE between '"+date.getText().toString()+"' and '"+date1.getText().toString()+"'";

    }
    else if(date.getTextSize()!=0)
    {

        where="T_DATE='"+date.getText().toString()+"'";
    }
    else if(pro.getSelectedItemPosition()==0 && allmemb.getSelectedItemPosition()==0 && allmod.getSelectedItemPosition()==0 && 
            allprio.getSelectedItemPosition()==0 && date.getTextSize()==0 && date1.getTextSize()==0 ) 
    {
        //Intent in=new Intent(getApplicationContext(),login.class);
        //startActivity(in);
        where="PROJECT='"+pro.getSelectedItemPosition()+"' and ASSIGNED_BY='"+allmemb.getSelectedItemPosition()+"' and MODULE='"+
        allmod.getSelectedItem()+"' and PRIORITY='"+allprio.getSelectedItem()+"' and  T_DATE='"+date.getText().toString()+"'"; 
    }    
    else if(pro.getSelectedItemPosition()>0)
    {
        where="PROJECT='"+pro.getSelectedItemPosition()+"'";
    }

    else if(allmemb.getSelectedItemPosition()!=0)
    {
        where="ASSIGNED_BY='"+allmemb.getSelectedItemPosition()+"'";
    }
    else if(allmod.getSelectedItemPosition()!=0)
    {
        where="MODULE='"+allmod.getSelectedItem()+"'";
    }       

    else if(allprio.getSelectedItemPosition()!=0)
    {
        where="PRIORITY='"+allprio.getSelectedItem()+"'";
    }

    else
    {
        //Toast.makeText(admin.this, "No Tasks to displays.....  ", Toast.LENGTH_SHORT).show();
    }

    Cursor cr6=sdb.query("TASK_DETAILS", new String[]{"USERID","ASSIGNED_BY","PROJECT","MODULE","PRIORITY","T_DATE","T_DESC","REMARKS"}, 
                where,null,null,null,null);

2 个答案:

答案 0 :(得分:1)

但是在第一个if-else开始之前的一个断点,调试它。可能因为条件失败而无法进入if-else。

答案 1 :(得分:0)

如果&&和是错误的,它不会检查其他条件,因为一个错误就足以使条件为假。