软工超越日报-预测页面改构 5/17

今天我们来包装下这个预测结果页面,光写在mainactivity上可太难看了!

还是用到了我们的老朋友——底边弹出框1

代码如下:

    //底部弹出框(预测)
    private void showBottomDialogB() {
        //1、使用Dialog、设置style
        final Dialog dialog = new Dialog(this, R.style.DialogTheme);
        //2、设置布局
        View view = View.inflate(this, R.layout.texter, null);
        dialog.setContentView(view);

        infoV xxi=dao.serVs((int)result[0]);

        Window window = dialog.getWindow();
        //设置弹出位置c
        window.setGravity(Gravity.BOTTOM);
        //设置弹出动画
        window.setWindowAnimations(R.style.main_menu_animStyle);
        //设置对话框大小
        window.setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        dialog.show();

        dialog.findViewById(R.id.returns).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                dialog.dismiss();
            }
        });

        show_text = "预测植物类型:" +xxi.getName()+
                "
预测症状:"+xxi.getSymptom() +
                "
概率:"+(result[1]*100) +"%"+
                "
时间:"+time+"ms";

        ImageView s=dialog.findViewById(R.id.image_view);
        s.setImageBitmap(bitmap);
        TextView m=dialog.findViewById(R.id.notnull);
        if(result[1]<0.6){
            m.setVisibility(View.VISIBLE);
        }
        Button kuwashi = dialog.findViewById(R.id.kuwashi);
        if(xxi.getVcode().equals("0")){
            kuwashi.setVisibility(View.GONE);
        }

        kuwashi.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent it =new Intent(MainActivity.this,version_detail.class);
                //用Bundle携带数据
                Bundle bundle=new Bundle();
                bundle.putInt("id", Integer.parseInt(xxi.getVcode()));
                it.putExtras(bundle);
                startActivity(it);
            }
        });

        SharedPreferences sc = MainActivity.this.getSharedPreferences("user", MODE_PRIVATE);
        String op=sc.getString("now_user","me")+sc.getString("password","0");
        String sp=sc.getString("now_model","base");
        TextView x= dialog.findViewById(R.id.result);
        x.setText(show_text);
        DecimalFormat decimalFormat=new DecimalFormat(".00");
        String bci=decimalFormat.format(result[1]*100);
        //数据库写入代码
        dao.insehis(image_path,""+xxi.getName()+xxi.getSymptom(),""+(int)result[0],xxi.getLevel(),dao.getTime(),""+bci,"never",op,provincex,cityx,districtx,sp);

    }

其他基本都大同小异啦

原文地址:https://www.cnblogs.com/Sakuraba/p/14911016.html