0

I'm loading the same page with different data. I've got it so it's listing my items and when I click one, it's sending the correct next page type and ID through. But it's still loading my first pages SQLStatement. The right things are being logged out.

Do I need to clear it down or something first?

Here is my code:

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();


    }




}
MissCoder87
  • 2,669
  • 10
  • 47
  • 82

1 Answers1

2

The data from your Intent looks correct, the problem is that in Java you must compare Strings like this:

if(dataType.equals("notset")) 

not:

if(dataType == "notset") 

Detailed explanation: How do I compare strings in Java?

Community
  • 1
  • 1
Sam
  • 86,580
  • 20
  • 181
  • 179