我在MainActivity中有按钮和TextView,我有另外三个活动示例(一,二,三,四)所以我想在TextView中文本为'hi'时然后当我点击按钮时,一个Activity将打开并且用文本等于'你好'它打开两个Activity,用'nice'文本Activity 3和'thanks'文本活动four.java将打开请帮帮我一个人
答案 0 :(得分:0)
btn = (Button) findViewById(R.id.btn);
tv = (TextView) findViewById(R.id.tv);
btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String s = tv.getText().toString();
if (s.equals("hi")) {
Intent intent = new Intent(this, One.class);
startActivity(intent);
}
if (s.equals("hello")) {
Intent intent = new Intent(this, Two.class);
startActivity(intent);
}
if (s.equals("nice")) {
Intent intent = new Intent(this, Three.class);
startActivity(intent);
}
if (s.equals("thanks")) {
Intent intent = new Intent(this, Four.class);
startActivity(intent);
}
}
});