我是android的新手,我试图通过Intent函数接收一个变量,并且根据变量的值应该显示一个contentview。
Bundle parametros = getIntent().getExtras();
String type = parametros.getString("tipo");
int accao = parametros.getInt("accao");
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (type=="medicamentos") {
Button voltar = (Button) findViewById(R.id.button1);
voltar.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
Intent medIntent = new Intent(view.getContext(), Listar.class);
startActivityForResult(medIntent, 0);
}
});
if (accao==1)
setContentView(R.layout.adicionar_medicamentos);
if (accao==2)
setContentView(R.layout.editar_medicamentos);
}
}
我做错了什么?谢谢