如何调用按钮背景,以及在if语句中匹配的活动布局。无法弄清楚如何做到这一点。
Context mContext = getApplicationContext();
final Dialog dialog = new Dialog(mContext);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
final Button quicktab = (Button) findViewById(R.id.btnA4);
quicktab.setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View v)
{
Button a4 = (Button)findViewById(R.id.btnA4);
if ( a4.getBackground() == (R.drawable.quick_btn_background)); ****ERROR****
{
if (this.setContentView() = this.setContentView(findViewById(R.layout.layout_24)); ****ERROR****
{
dialog.setContentView(R.layout.popup_24);
}
else (this.setContentView() = this.setContentView(findViewById(R.layout.layout_63)); ****ERROR****
{
dialog.setContentView(R.layout.popup_63);
}
}
else
{
finish();
}
}
});
编码或标记的所有错误。你能帮忙的话,我会很高兴。似乎无法找到与此类if语句相关的任何内容。
的 的 ** * * 更新的 * ** * **** 新代码仍有错误。在getBackground代码上,我得到错误:不兼容的操作数类型Drawable和int。在getContentView代码中,我得到错误:create method getContentView。
Context mContext = getApplicationContext();
final Dialog dialog = new Dialog(mContext);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
final Button quicktab = (Button) findViewById(R.id.btnA4);
quicktab.setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View v)
{
Button a4 = (Button)findViewById(R.id.btnA4);
if (a4.getBackground() == R.drawable.quick_btn_background)
{
if (this.getContentView() == R.layout.layout_24)
{
dialog.setContentView(R.layout.popup_24);
}
else if(this.getContentView() == R.layout.layout_63)
{
dialog.setContentView(R.layout.popup_63);
}
}
else finish();
}
});
答案 0 :(得分:2)
请不要在你的if
语句中添加分号,并添加一些缺少的右括号,语法应该没问题。像这样:
Context mContext = getApplicationContext();
final Dialog dialog = new Dialog(mContext);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
final Button quicktab = (Button) findViewById(R.id.btnA4);
quicktab.setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View v)
{
Button a4 = (Button) findViewById(R.id.btnA4);
if (a4.getBackground() == R.drawable.quick_btn_background)
{
if (this.setContentView() == this.setContentView(findViewById(R.layout.layout_24)))
{
dialog.setContentView(R.layout.popup_24);
}
else if(this.setContentView() == this.setContentView(findViewById(R.layout.layout_63))
{
dialog.setContentView(R.layout.popup_63);
}
else finish();
}
}
});
但是,我完全不确定你需要比较this.setContentView() == this.setContentView(...)
。你不是指某处getContentView
吗?希望这有帮助,祝你好运......
答案 1 :(得分:0)
R.drawable.quick_btn_background
是一个数字资源ID(int或long - 不确定),而a4.getBackground()
返回Drawable
。所以这两者的比较毫无意义。