首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >有什么Android的编码小提示吗?

有什么Android的编码小提示吗?
EN

Stack Overflow用户
提问于 2018-07-23 04:52:11
回答 1查看 0关注 0票数 0

以下是我写的代码:

代码语言:txt
复制
public class ProblemsDescription extends Fragment {
    static final int REQUEST_IMAGE_CAPTURE = 1;
    private Report report = null;
    private EditText text = null;
    private Button button = null, bottoneph = null, bottonelc = null;
    private FragmentTransaction transaction;
    private LocationManager lm;
    private LocationListener ls;
    private TextView text2=null;
    private double[] locazione= new double[2];

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {

        return inflater.inflate(R.layout.fragment_problems_description_maps, container, false);
    }

    @Override
    public void onActivityCreated(Bundle save) {
        super.onActivityCreated(save);

    }

    @Override
    public void onResume() {
        super.onResume();
        text2=(TextView) getActivity().findViewById(R.id.textView);
        button = (Button) getActivity().findViewById(R.id.button3);
        bottoneph = (Button) getActivity().findViewById(R.id.button4);
        bottonelc = (Button) getActivity().findViewById(R.id.button5);
        text = (EditText) getActivity().findViewById(R.id.editText);
        lm = (LocationManager) getActivity().getSystemService(LOCATION_SERVICE);
        ls = new LocationListener() {
            @Override
            public void onLocationChanged(Location location){
text2.append(location.getLatitude() + " " + location.getLongitude());

            }

            @Override
            public void onStatusChanged(String provider, int status, Bundle extras) {

            }

            @Override
            public void onProviderEnabled(String provider) {

            }

            @Override
            public void onProviderDisabled(String provider) {
                Intent intent= new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
                startActivity(intent);

            }
        }; if (ActivityCompat.checkSelfPermission(getContext(), Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(getContext(), Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
            requestPermissions(new String[]{
                    Manifest.permission.ACCESS_FINE_LOCATION, Manifest.permission.ACCESS_COARSE_LOCATION, Manifest.permission.INTERNET
            },10);
            return;
        }else
        {
            configurebutton();
        }



        bottone.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
              report.setReport(text.getText().toString());

            }
        });


        bottoneph.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dispatchTakePictureIntent();
            }
        });
        }



    private void dispatchTakePictureIntent() {
        Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
        if (takePictureIntent.resolveActivity(getActivity().getPackageManager()) != null) {
            startActivityForResult(takePictureIntent, REQUEST_IMAGE_CAPTURE);
        }
    }

    @Override
    public void onRequestPermissionsResult(int requestCode, String[]permission, int[]grantResults)
    {
        switch(requestCode)
        {
            case 10:
                if (grantResults.length>0 && grantResults[0] == PackageManager.PERMISSION_GRANTED)
                    configurebutton();
                return;
        }
    }
    private void configurebutton() {
        bottonelc.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                lm.requestLocationUpdates("gps", 5000, 0, ls);
            }
        });

    }

    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data)
    {
        super.onActivityResult(requestCode, resultCode, data);
        Bitmap bitmap= (Bitmap) data.getExtras().get("data");
        report.setPhoto(bitmap);
    }

    public void setSegnalazione(Segnalazione segnalazione)
    {
        this.report=report;
    }
}
EN

回答 1

Stack Overflow用户

发布于 2018-07-23 13:55:32

使一个私有的voidinit()函数并在其中初始化变量,就能清楚的知道这是用于诸如findviewbyid之类的东西。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/-100005626

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档