我正在使用不同的数据加载同一页面。我有它,所以它列出了我的项目,当我单击一个时,它会发送正确的下一页类型和 ID。但它仍在加载我的第一页 SQLStatement。正确的事情正在被注销。
我需要先清除它还是什么?
这是我的代码:
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();
}
}