如何在android中的单个EditText中添加多个位置。我们想要创建位置的标记。
答案 0 :(得分:1)
我必须编写代码以在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);
}