2012-10-04 18 views
0

我使用不同的數據加載相同的頁面。我已經知道了,所以它列出了我的項目,當我點擊它時,它會發送正確的下一頁類型和ID。但它仍然加載我的第一頁SQLStatement。正確的事情正在被註銷。Android - 使用不同的數據加載相同的意圖

我是否需要首先清除它?

這裏是我的代碼:

public class LocationListView extends Activity { 

String SQLStatement; 
String itemID = "1001-0001021"; 
String Type; 
; 


    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_location_list_view); 

     Bundle extras = getIntent().getExtras(); 
     String dataType; 
     String dataID; 

     if (extras != null) { 
      dataType = extras.getString("Type"); 
      dataID = extras.getString("ID"); 

     } else { 
      dataType = "notset"; 
      dataID = "notset"; 
     } 


     File dbfile = new File(Global.currentDBfull); 
     SQLiteDatabase db = SQLiteDatabase.openOrCreateDatabase(dbfile, null); 

     if(dataType == "notset") { 

      SQLStatement = "select * from stationobjects where stationid= " + Global.StationID + " and objectid=0"; 
      Type = "Room"; 

     } else if(dataType == "Room") { 

      SQLStatement = "select * from stationobjects where stationid= " + Global.StationID + " and objectid=1001 and diagramid like '"+ itemID +"%'"; 
      Type = "Area"; 

      Context context = getApplicationContext(); 
      CharSequence text = "Hello toast!"; 
      int duration = Toast.LENGTH_SHORT; 

      Toast toast = Toast.makeText(context, text, duration); 
      toast.show(); 

     } else if(dataType == "Area") { 

      Type = "Zone"; 
     } else if(dataType == "Zone") { 


     } else { 

      SQLStatement = "select * from stationobjects where stationid= " + Global.StationID + " and objectid=0"; 
      Type = "Room"; 
     } 


     Cursor c = db.rawQuery(SQLStatement, null); 
     if(c.getCount() != 0) { 

     Log.e("LocationListView", "Found Items"); 

     c.moveToFirst(); 

     ArrayList<String> mItemName = new ArrayList<String>(); 
     final ArrayList<String> mItemID = new ArrayList<String>(); 

     c.moveToFirst(); 
     while(!c.isAfterLast()) { 
      mItemName.add(c.getString(c.getColumnIndex("Name"))); 
      mItemID.add(c.getString(c.getColumnIndex("StationObjectID"))); 
      c.moveToNext(); 
     } 

     final ListView listView = (ListView) findViewById(R.id.lvLocation); 
     final ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, 
       android.R.layout.simple_list_item_1, android.R.id.text1, mItemName); 

     int[] colors = {0, 0xFFFF0000, 0}; 
     listView.setDivider(new GradientDrawable(Orientation.RIGHT_LEFT, colors)); 
     listView.setDividerHeight(1); 
     listView.setAdapter(adapter); 

     listView.setClickable(true); 
     listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { 

      @Override 
      public void onItemClick(AdapterView<?> arg0, View arg1, int position, long arg3) { 

      Object o = listView.getItemAtPosition(position); 
      String StationObjectID = mItemID.get(position); 
      Log.e("LocationListView", "" + o); 
      Log.e("LocationListView", "" + StationObjectID); 


      startActivityForResult(SwapPage, 0); 

      } 
     }); 

     } else { 

      Log.e("LocationListView", "Not Found Items"); 
      Context context = getApplicationContext(); 
      CharSequence text = "Sorry No data returned"; 
      int duration = Toast.LENGTH_LONG; 

      Toast toast = Toast.makeText(context, text, duration); 
      toast.show(); 
     } 

     db.close(); 


    } 




} 

回答

2

從你的意圖的數據看起來是正確的,問題是,在Java中你必須compare Strings這樣的:

if(dataType.equals("notset")) 

不是:

if(dataType == "notset") 

詳細說明:How do I compare strings in Java?

+0

當然!我頭腦中的語言太多了。謝了哥們 – TMB87

相關問題