我知道这已被问了一百万次,但没有一次让我解决了我的问题。 onclicklistener不会激活任何按钮的代码。以下是适用于五个按钮的不同部分。
Button btnGuysMax;
Button btnGuysMedium;
Button btnEven;
Button btnGirlsMedium;
Button btnGirlsMax;
....
private void init()
{
datasource = new BarsDataSource(this);
datasource.open();
Intent intent = getIntent();
long id = intent.getLongExtra("bar_id",0);
bar = datasource.getBarById(id);
title = (TextView)findViewById(R.id.title);
btnGuysMax = (Button)findViewById(R.id.btnGuysMax);
btnGuysMedium = (Button)findViewById(R.id.btnGuysMedium);
btnEven = (Button)findViewById(R.id.btnEven);
btnGirlsMedium = (Button)findViewById(R.id.btnGirlsMedium);
btnGirlsMax = (Button)findViewById(R.id.btnGirlsMax);
......
btnGuysMax.setOnClickListener(this);
btnGuysMedium.setOnClickListener(this);
btnEven.setOnClickListener(this);
btnGirlsMedium.setOnClickListener(this);
btnGirlsMax.setOnClickListener(this);
.....
@Override
public void onClick(View view)
{
//resetButtons();
switch (view.getId()) {
case R.id.btnGuysMax:
//bar.setSexRatio(-2);
//btnGuysMax.setBackgroundColor(guysMaxColor);
Toast.makeText(this,"Max clicked!",Toast.LENGTH_LONG);
break;
case R.id.btnGuysMedium:
bar.setSexRatio(-1);
Toast.makeText(this,"Medium clicked!",Toast.LENGTH_LONG);
//btnGuysMedium.setBackgroundColor(guysMediumColor);
break;
case R.id.btnEven:
bar.setSexRatio(0);
//Toast.makeText(this,"Medium clicked!",Toast.LENGTH_LONG);
break;
case R.id.btnGirlsMedium:
bar.setSexRatio(1);
//btnGirlsMedium.setBackgroundColor(girlsMediumColor);
break;
case R.id.btnGirlsMax:
bar.setSexRatio(2);
break;
.....
答案 0 :(得分:1)
要显示祝酒词,您需要调用show方法。
尝试:
Toast.makeText(this,"message",Toast.LENGTH_LONG).show();
答案 1 :(得分:0)
尝试做:
@Override
public void onClickListener(View view)
{
而不是:
@Override
public void onClick(View view)
{