我的代码检查if mode="search" true
它何时进入第二个活动。如果是,那么School_name
就是这个值,否则当用户点击ImageView
或时设置这个值ListView
。
问题是,如果我单击表单 imageview 返回 true,则此语句if (( mode.compareTo("search")==0) )
并从if (( mode.compareTo("search")==0) )
if is flase not go else 语句中获取值告诉我我的代码有什么问题
public class HomeMenu extends Activity {
public static String mode;
editText2=(EditText) findViewById(R.id.editText2);
ImageView imageView1 = (ImageView) findViewById(R.id.imageView1);
imageView1.setOnClickListener(new OnClickListener() {
@Override
public void onClick (View v){
mode = "search";
Intent iMenuList = new Intent(HomeMenu.this, SecondStep.class);
Serachvalue = editText2.getText().toString();
iMenuList.putExtra("Serachvalue", Serachvalue);
startActivity(iMenuList);
}
});
listMainMenuhome=(ListView) findViewById(R.id.listMainMenuhome);
listMainMenuhome.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick (AdapterView < ? > arg0, View arg1,int position, long arg3){
Intent iMenuList = new Intent(HomeMenu.this, SecondStep.class);
iMenuList.putExtra("School_name", Category_name.get(position));
startActivity(iMenuList);
}
});
public class SecondStep extends Activity {
String mode;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.secondstep);
mode = HomeMenu.mode;
if ((mode.compareTo("search") == 0)) {
Bundle bundle = this.getIntent().getExtras();
School_name = bundle.getString("Serachvalue");
} else {
Bundle bundle = this.getIntent().getExtras();
School_name = bundle.getString("School_name");
}
}
}