Currently when I click my button it uses the method startActivityForResult(); It finds the answer and returns.
The only problem is once it returns it will start the activity again. Personally I think its completely pointless to have a method that can only be run once. Surely there must be a flag that can be given to the method in order to tell it to run as many times as wanted?
I've read the javadoc and it doesn't seem to help because it says its a one time use, unless I'm reading it wrong?
IN MY SEARCH ACTIVITY:
private OnItemClickListener listListener = new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
// TODO Auto-generated method stub
String text = (String) ((TextView) arg1).getText();
String[] selected = text.split(" - ");
selected[0] = selected[0].replace(' ', '_');
Log.w("COMPANY", selected[0]);
Log.w("PART", selected[1]);
Intent data = new Intent();
data.putExtra("key", selected);
setResult(RESULT_OK, data);
finish();
// startActivity(switch2);
}
};
IN MY MAIN ACTIVITY (IN Button LISTENER)
if (search.isPressed() && searchPressed == false) {
// show search list
Intent switch1 = new Intent(MainActivity.this, SearchActivity.class);
startActivityForResult(switch1, 0);
}
@Override
protected void onActivityResult(int req, int resp, Intent data) {
super.onActivityResult(req, resp, data);
searchPressed = true;
Bundle searched = data.getExtras();
String[] newItem = searched.getStringArray("key");
if (newItem[0].endsWith("_")) {
handleXML(1);
tv1.setText("Higher");
tv2.setText("Lower");
} else {
handleXML(0);
tv1.setText("Wear Resistance");
tv2.setText("Tougher");
}
competitors = h.competitors;
String[] piece = competitors.findCompanyParts(newItem);
assignMaterials(piece);
window.setVisibility(VISIBLE);
grade.setVisibility(INVISIBLE);
geo.setVisibility(INVISIBLE);
s1.setVisibility(INVISIBLE);
s2.setVisibility(INVISIBLE);
search.setVisibility(INVISIBLE);
help.setVisibility(INVISIBLE);
myTabHost.setCurrentTab(0);
}