Просто отправьте xml байты напрямую:
#!/usr/bin/env python2
# -*- coding: utf-8 -*-
import requests
xml = """<?xml version='1.0' encoding='utf-8'?>
<a>б</a>"""
headers = {'Content-Type': 'application/xml'} # set what your server accepts
print requests.post('http://httpbin.org/post', data=xml, headers=headers).text
{
"origin": "x.x.x.x",
"files": {},
"form": {},
"url": "http://httpbin.org/post",
"args": {},
"headers": {
"Content-Length": "48",
"Accept-Encoding": "identity, deflate, compress, gzip",
"Connection": "keep-alive",
"Accept": "*/*",
"User-Agent": "python-requests/0.13.9 CPython/2.7.3 Linux/3.2.0-30-generic",
"Host": "httpbin.org",
"Content-Type": "application/xml"
},
"json": null,
"data": "<?xml version='1.0' encoding='utf-8'?>\n<a>\u0431</a>"
}
Вы можете просто создать новый массив, который будет содержать только адреса. Но лучшим подходом было бы создание пользовательского класса (назовем его Product
), который просто содержит геттеры и сеттеры. Затем вы меняете ArrayAdapter<String>
на ArrayAdapter<Product>
. Настраивать адаптеры Array довольно просто:
https://www.journaldev.com/10416/android-listview-with-custom-adapter-example-tutorial
РЕДАКТИРОВАТЬ Вот плохое решение, которое я упомянул. Другой занял бы слишком много времени, чтобы я мог напечатать (но вы должны действительно изучить это, потому что это супер распространенная задача в Android):
public class Index extends AppCompatActivity implements
GoogleMap.OnMyLocationButtonClickListener,
GoogleMap.OnMyLocationClickListener, OnMapReadyCallback,
ActivityCompat.OnRequestPermissionsResultCallback {
public static String[] account;
private static final int LOCATION_PERMISSION_REQUEST_CODE = 1;
private boolean mPermissionDenied = false;
private GoogleMap mMap;
String[][] mobileArray = {
new String[] {"150 Goyeau St, Windsor, ON N9A 6J5","Product 1","N/A","3:30pm"},
new String[] {"2000 Talbot Road West, Windsor, ON N9A 6S4","Product 2","N/A","4:00pm"},
new String[] {"350 City Hall Square W, Windsor, ON N9A 6S1","Product 3","N/A","4:30pm"}
};
String[] addressArray = new String[mobileArray.length];
for (int i=0; i<mobileArray.length; i++) {
addressArray[i] = mobileArray[0][i];
}
@Override
public void onWindowFocusChanged(boolean hasFocus) {
super.onWindowFocusChanged(hasFocus);
if (hasFocus) {
hideSystemUI();
}
}
private void hideSystemUI() {
View decorView = getWindow().getDecorView();
decorView.setSystemUiVisibility(
View.SYSTEM_UI_FLAG_IMMERSIVE
| View.SYSTEM_UI_FLAG_LAYOUT_STABLE
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_FULLSCREEN);
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
TextView tVDriver = (TextView)findViewById(R.id.tVDriver);
tVDriver.setText(account[0]);
final TextView tVSpecial = (TextView)findViewById(R.id.tVSpecial);
final TextView tVProduct = (TextView)findViewById(R.id.tVProduct);
ArrayAdapter adapter = new ArrayAdapter<String>(this, R.layout.listview, addressArray);
ListView listView = (ListView) findViewById(R.id.lVDelivery);
listView.setAdapter(adapter);
listView.setOnItemClickListener(new AdapterView.OnItemClickListener(){
@Override
public void onItemClick(AdapterView<?>adapter, View v, int position, long id){
tVSpecial.setText(mobileArray[position][2]);
tVProduct.setText(mobileArray[position][1]);
}
});
SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map);
mapFragment.getMapAsync(this);
}
@Override
public void onMapReady(GoogleMap map) {
mMap = map;
mMap.setOnMyLocationButtonClickListener(this);
mMap.setOnMyLocationClickListener(this);
enableMyLocation();
}
private void enableMyLocation() {
if (ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION)
!= PackageManager.PERMISSION_GRANTED) {
PermissionUtils.requestPermission(this, LOCATION_PERMISSION_REQUEST_CODE,
Manifest.permission.ACCESS_FINE_LOCATION, true);
} else if (mMap != null) {
mMap.setMyLocationEnabled(true);
}
}
@Override
public boolean onMyLocationButtonClick() {
Toast.makeText(this, "MyLocation button clicked", Toast.LENGTH_SHORT).show();
return false;
}
@Override
public void onMyLocationClick(@NonNull Location location) {
Toast.makeText(this, "Current location:\n" + location, Toast.LENGTH_LONG).show();
}
@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
if (requestCode != LOCATION_PERMISSION_REQUEST_CODE) {
return;
}
if (PermissionUtils.isPermissionGranted(permissions, grantResults,
Manifest.permission.ACCESS_FINE_LOCATION)) {
enableMyLocation();
} else {
mPermissionDenied = true;
}
}
@Override
protected void onResumeFragments() {
super.onResumeFragments();
if (mPermissionDenied) {
showMissingPermissionError();
mPermissionDenied = false;
}
}
private void showMissingPermissionError() {
PermissionUtils.PermissionDeniedDialog
.newInstance(true).show(getSupportFragmentManager(), "dialog");
}
}