2

文字列は正常に動作していますが、 double はどうですか?

これが私のコードです

ImageView protect_me_btn=(ImageView) findViewById(R.id.protect_me_btn);
protect_me_btn.setOnClickListener(new OnClickListener() {
    @Override
    public void onClick(View v) {
        pbupdate.setVisibility(4);
        String lat= Double.toString(latitude);
        Intent inte=new Intent(getApplicationContext(),set_alaram.class);
        Bundle lati=new Bundle();
        lati.putString("first",lat);
        inte.putExtras(lati);
        startActivity(inte);                    
    }
});
4

2 に答える 2

4

set_alaramアクティビティに関してバンドルを使用してDouble値を送信します。

protect_me_btn.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            pbupdate.setVisibility(4);
            String lat= Double.toString(latitude);
            Intent inte=new Intent(getApplicationContext(), set_alaram.class);
            Bundle lati=new Bundle();
            lati.putString("first",lat);
            lati.putDouble("lat", latitude); //<< send double using putDouble
            inte.putExtras(lati);
            startActivity(inte);                    
        }
    });

アクティビティでset_alaramは、バンドルからDouble値を取得します。

Bundle bundle = this.getIntent().getExtras();

Double lat = bundle.getDouble("lat");
于 2012-12-22T08:39:58.950 に答える
0

この方法で、double値をバンドルで送信できます。

Intent intent = new Intent(CurrentActivity.this, DestinationActivity.class);
    Bundle bundle = new Bundle();
    bundle.putDouble("key", yourDoubleValue);
    intent.putExtras(bundle);
    startActivity(intent);

あなたの別の活動では:

Bundle bundle = getIntent().getExtras();
double passedDoubleValue = bundle.getDouble("key");

お役に立てれば。

于 2012-12-22T08:38:30.710 に答える