扫描二维码和生成二维码
2015-07-13 13:41
288 查看
public class MainActivity extends Activity implements OnClickListener{ private TextView textView; private EditText editText1; private Button button1; private Button saomao; private ImageView imageView1; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); saomao = (Button) findViewById(R.id.saomao); textView = (TextView) findViewById(R.id.textView1); button1 = (Button) findViewById(R.id.button1); editText1 = (EditText) findViewById(R.id.editText1); imageView1 = (ImageView) findViewById(R.id.imageView1); saomao.setOnClickListener(this); button1.setOnClickListener(this); } @Override public void onClick(View v) { // TODO Auto-generated method stub switch (v.getId()) { case R.id.saomao: Intent intent = new Intent(this, CaptureActivity.class); startActivityForResult(intent, 0); break; case R.id.button1: String string = editText1.getText().toString().trim(); if (string.equals("")) { Toast.makeText(MainActivity.this, "请输入文本", 0).show(); }else { try { Bitmap bitmap = EncodingHandler.createQRCode(string, 400); imageView1.setImageBitmap(bitmap); } catch (WriterException e) { // TODO Auto-generated catch block e.printStackTrace(); } } break; default: break; } } @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { // TODO Auto-generated method stub super.onActivityResult(requestCode, resultCode, data); if (resultCode == RESULT_OK) { String result = data.getExtras().getString("result"); textView.setText(result); } } }源码下载
相关文章推荐
- 泛函编程(33)-泛函IO:Free Functor - Coyoneda
- JS遮罩层弹框效果
- WebApi常见4xx错误总结!!!
- Nessus漏洞扫描教程之使用Nmap工具扫描识别指纹
- Grunt配置
- The connection to adb is down, and a severe error has occured问题解决
- 宝宝四岁多了该如何教育
- 无人机时代:天长地久还要靠平台化
- Android中如何解析JSON数据
- [LeetCode] Reverse Linked List
- @SuppressWarnings注解
- 怎样教四岁的孩子学画画
- grep命令的详细使用方法
- nginx配置文件详解
- 约瑟夫环问题
- 网站怎么运转的
- 清理html中空白符/空格/换行在行内元素中产生的间距
- jquery检测浏览器版本
- 手机APP设计网
- 约瑟夫环问题