import android.content.Intent; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.view.View; import android.widget.Button; public class IndexActivity extends AppCompatActivity { private Button btnS01E01; private Button btnS01E02; private Button btnS01E03; private Button btnS01E04; private Button btnS01E05; private Button btnS01E06; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_index); btnS01E01 = (Button)findViewById(R.id.btnS01E01); btnS01E02 = (Button)findViewById(R.id.btnS01E02); btnS01E03 = (Button)findViewById(R.id.btnS01E03); btnS01E04 = (Button)findViewById(R.id.btnS01E04); btnS01E05 = (Button)findViewById(R.id.btnS01E05); btnS01E06 = (Button)findViewById(R.id.btnS01E06); btnS01E01.setOnClickListener(new ButtonListener()); btnS01E02.setOnClickListener(new ButtonListener()); btnS01E03.setOnClickListener(new ButtonListener()); btnS01E04.setOnClickListener(new ButtonListener()); btnS01E05.setOnClickListener(new ButtonListener()); btnS01E06.setOnClickListener(new ButtonListener()); } class ButtonListener implements View.OnClickListener{ @Override public void onClick(View v) { switch (v.getId()) { case R.id.btnS01E01: startActivity(new Intent(IndexActivity.this, S01E01Activity.class)); break; case R.id.btnS01E02: startActivity(new Intent(IndexActivity.this, S01E02Activity.class)); break; case R.id.btnS01E03: startActivity(new Intent(IndexActivity.this, S01E03Activity.class)); break; case R.id.btnS01E04: startActivity(new Intent(IndexActivity.this, S01E04Activity.class)); break; case R.id.btnS01E05: startActivity(new Intent(IndexActivity.this, S01E05Activity.class)); break; case R.id.btnS01E06: startActivity(new Intent(IndexActivity.this, S01E06Activity.class)); break; } } } }
一个监听器绑定多个按钮控件
最新推荐文章于 2024-01-30 17:31:48 发布