2013-07-19 162 views
-8

我的問題是,當我在if條件中使用多個語句時,如(pro.getSelectedItemPosition()!=0 && allmemb.getSelectedItemPosition()!=0),它會被檢查,但如果我使用單個語句如(pro.getSelectedItemPosition()!=0),則不檢查條件。if-else if語句在android中不能正常工作

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); 
+4

你想幹什麼?它實際上做了什麼。 「不工作」非常模糊 – doctorlove

+0

我認爲你沒有做功課:) –

+0

你爲什麼需要這樣做?這太可怕了,同意塔倫! – Shraddha

回答

0

如果其中一個& &的陳述是錯誤的,它不會檢查其他條件,因爲一個錯誤足以使條件成爲假。

1

但是在第一個if-else開始之前的一個斷點,調試它。可能是因爲條件失敗而導致其他內容不能進入。