当您尝试通过单击按钮来更改活动时,我发现您必须使用 Intent。但是在我的代码中使用它似乎不起作用。我的代码有问题吗?
public class SearchActivity extends Activity implements OnClickListener{
private ListView recipes;
Intent intent;
Button button;
EditText input;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.searchlist);
//EditText input = (EditText)findViewById(R.id.recipeName);
button = (Button)findViewById(R.id.submit);
input = (EditText)findViewById(R.id.recipeName);
//recipes = (ListView)findViewById(R.id.recipes);
//recipes.setAdapter(new ArrayAdapter<String> (this, R.layout.main, getResources().getStringArray(R.array.BaconSandwich)));
button.setOnClickListener(this);
}
public void onClick(View clicked) {
String value = input.getText().toString();
Toast.makeText(this, value, Toast.LENGTH_SHORT).show();
if(clicked == button) {
recipes = (ListView)findViewById(R.id.recipes);
Toast.makeText(this, "It is working for this item.", Toast.LENGTH_SHORT).show();
Intent i = new Intent(SearchActivity.this, RecipeMethodActivity.class);
SearchActivity.this.startActivity(i);
}
}
我不确定这是否只是一个简单的命名错误,或者我调用它的方式是错误的。任何帮助都会很棒。
此外,我已将要更改为 (RecipeMethodActivity) 的活动添加到 Android 清单中。