Я пытаюсь использовать кнопку, чтобы начать новое действие, подобное этому:
public class MainActivity extends Activity implements OnClickListener {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
((Button) findViewById(R.id.button1)).setOnClickListener(this);
((Button) findViewById(R.id.button2)).setOnClickListener(this);
}
public void onClick(View view) {
Button clickedBtn = (Button) view;
switch (clickedBtn.getId()) {
case R.id.button1: startActivity(new Intent(this, NewActivity.class));
break;
case R.id.button2: startActivity(new Intent(this, AnotherActivity.class));
break;
}
}
}
Но, кажется, ничего не происходит, когда я нажимаю на любую кнопку. Я думаю, это потому, что метод onClick не знает, какая кнопка нажата ... но я не уверен, как это исправить ... пожалуйста, совет, спасибо!
Редактировать: добавлен файл XML
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:background="#000000">
<ScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<Button android:id="@+id/button1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="first button" />
<Button android:id="@+id/button2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="second button" />
</LinearLayout>
</ScrollView>
</LinearLayout>