根据 TextView 值打开 Activity
Open Activity depending on TextView value
我在 MainActivity 中有按钮和 TextView,我还有另外三个活动示例(一、二、三、四)所以我想当文本在 TextView 中时 'hi' 然后当我点击按钮第一个 Activity 将打开,文本等于 'hello' 它打开两个 Activity,文本 'nice' 第三个 [=16] =] 文本 activity four.java 将打开请帮助我
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);
}
}
});
我在 MainActivity 中有按钮和 TextView,我还有另外三个活动示例(一、二、三、四)所以我想当文本在 TextView 中时 'hi' 然后当我点击按钮第一个 Activity 将打开,文本等于 'hello' 它打开两个 Activity,文本 'nice' 第三个 [=16] =] 文本 activity four.java 将打开请帮助我
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);
}
}
});