1 选择 imagebutton
2 在imagedraw下面放张图tu1.jpg
3主代码如下
import android.content.Intent; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.view.View; import android.widget.ImageButton; import android.widget.TextView; public class MainActivity extends AppCompatActivity { private ImageButton imgbt = null; private TextView textx = null; private TextView texty = null; private TextView textz = null; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); imgbt = (ImageButton) findViewById(R.id.imageButton); textx = (TextView) findViewById(R.id.editText); texty = (TextView) findViewById(R.id.editText2); textz = (TextView) findViewById(R.id.editText3); imgbt.setImageDrawable(getResources().getDrawable(R.drawable.tu1)); imgbt.setOnClickListener(listener); } private View.OnClickListener listener = new View.OnClickListener() { public void onClick(View v) { if (v == imgbt) { double m_x,m_y,m_z; m_x= Double.parseDouble(textx.getText().toString()); m_y= Double.parseDouble(texty.getText().toString()); m_z = m_x+m_y; textz.setText(String.valueOf(m_z)); } } }; }
本文介绍了一个简单的 Android 应用示例,使用 ImageButton 控件实现两个数值输入并进行加法运算的功能。通过设置监听器来响应按钮点击事件,并更新结果显示。
8307

被折叠的 条评论
为什么被折叠?



