简体   繁体   English

如何在Android中的单个EditText中添加多个位置

[英]How to add multiple locations in single EditText in android

如何在Android的单个EditText中添加多个位置。我们要创建位置标签

I have to written code to add multiple location in single EditText in android. 我必须编写代码以在android的单个EditText中添加多个位置。

 void updateAddressLayout() {

    final ViewGroup locationGroup = (ViewGroup) getActivity().findViewById(R.id.locationsLayout);
    for (int i = locationGroup.getChildCount() - 1; i >= 0; i--) {
        locationGroup.removeViewAt(i);
    }
    final LayoutInflater inflater =getActivity().getLayoutInflater();
    for (int i=0; i < mylocations.size(); i++){
        final View locationView = inflater.inflate(R.layout.include_location_tag_chip, locationGroup, false);
        final TextView locationText = (TextView)locationView.findViewById(R.id.info_text);
        final ImageView delImage = (ImageView)locationView.findViewById(R.id.icon_del);
        final String primaryAddress = mylocations.get(i).getAddressLine(0) + " " + mylocations.get(i).getAddressLine(1) + " " + mylocations.get(i).getLocality() + " " + mylocations.get(i).getPostalCode();
        locationText.setText(primaryAddress);
        final int finalI = i;
        delImage.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                new AlertDialog.Builder(getActivity())
                        .setTitle("Alert!")
                        .setMessage("Are you sure you want to delete location ")
                        .setPositiveButton("Yes", new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                               mylocations.remove(finalI);
                                locationGroup.removeViewAt(finalI);
                            }
                        }).setNegativeButton("No", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        dialog.dismiss();
                    }
                }).show();
            }
        });
        locationGroup.addView(locationView);
    }
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {

    if (resultCode == Activity.RESULT_OK) {
        if (requestCode == REQUEST_GET_LOCATION) {
            mCurrentAddress = data.getParcelableExtra("LOC_ADDRESS");
            Toast.makeText(getActivity(),"You can add only three locations", Toast.LENGTH_LONG).show();
            if (mCurrentAddress.getAddressLine(0) != null || mCurrentAddress.getAddressLine(1) != null || mCurrentAddress.getLocality() != null || mCurrentAddress.getPostalCode() != null) {
                    if (mylocations.size() <3) {
                    mylocations.put(mylocations.size(), (Address) data.getParcelableExtra("LOC_ADDRESS"));
                }
                updateAddressLayout();
            }
            return;
        }
    }
    if (resultCode == Activity.RESULT_CANCELED && requestCode == REQUEST_GET_LOCATION) {
    }
    super.onActivityResult(requestCode, resultCode, data);
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM