Android 在改造中动态更改Url
我正在进行改造,在为查询动态更改Url时遇到了一个问题。 我有一个这样的界面Android 在改造中动态更改Url,android,url,retrofit,Android,Url,Retrofit,我正在进行改造,在为查询动态更改Url时遇到了一个问题。 我有一个这样的界面 public interface RetrofitObjectAPI { @GET("data/2.5/weather") Call<Weather> getWeatherDetails(@Query("weather") String string); } ObjectAPI的公共接口{ @获取(“数据/2.5/天气”) 调用getWeatherDetails(@Query(“weather”)字符串
public interface RetrofitObjectAPI {
@GET("data/2.5/weather")
Call<Weather> getWeatherDetails(@Query("weather") String string);
}
ObjectAPI的公共接口{
@获取(“数据/2.5/天气”)
调用getWeatherDetails(@Query(“weather”)字符串);
}
在我的MainActivity.java中
String url = "http://api.openweathermap.org/";
String API_KEY="00f05ed7a5400d4d7765e69330e28ab4";
String place="Mumbai,india";
String finalUrl="weather?q="+place+"&appid="+API_KEY;
@Override
protected void onResume() {
super.onResume();
Retrofit retrofit = new Retrofit.Builder()
.baseUrl(url)
.addConverterFactory(GsonConverterFactory.create())
.build();
RetrofitObjectAPI service = retrofit.create(RetrofitObjectAPI.class);
Call<Weather> call = service.getWeatherDetails(finalUrl);
call.enqueue(new Callback<Weather>() {
@Override
public void onResponse(Response<Weather> response, Retrofit retrofit) {
stringurl=”http://api.openweathermap.org/";
字符串API_KEY=“00F05ED7A5400D4D7765E6930E28AB4”;
String place=“印度孟买”;
字符串finalUrl=“weather?q=“+place+”&appid=“+API\u KEY;
@凌驾
受保护的void onResume(){
super.onResume();
改装改装=新改装.Builder()
.baseUrl(url)
.addConverterFactory(GsonConverterFactory.create())
.build();
RefundationObjectAPI服务=Refundation.create(RefundationObjectAPI.class);
Call Call=service.getWeatherDetails(finalUrl);
call.enqueue(新回调(){
@凌驾
公共响应(响应、改装){
我的天气预报
public class Weather {
@SerializedName("coord")
@Expose
private Coord coord;
@SerializedName("weather")
@Expose
private List<Weather_> weather = null;
@SerializedName("base")
@Expose
private String base;
@SerializedName("main")
@Expose
private Main main;
@SerializedName("visibility")
@Expose
private Integer visibility;
@SerializedName("wind")
@Expose
private Wind wind;
@SerializedName("clouds")
@Expose
private Clouds clouds;
@SerializedName("dt")
@Expose
private Integer dt;
@SerializedName("sys")
@Expose
private Sys sys;
@SerializedName("id")
@Expose
private Integer id;
@SerializedName("name")
@Expose
private String name;
@SerializedName("cod")
@Expose
private Integer cod;
public Coord getCoord() {
return coord;
}
public void setCoord(Coord coord) {
this.coord = coord;
}
public List<Weather_> getWeather() {
return weather;
}
public void setWeather(List<Weather_> weather) {
this.weather = weather;
}
public String getBase() {
return base;
}
public void setBase(String base) {
this.base = base;
}
public Main getMain() {
return main;
}
public void setMain(Main main) {
this.main = main;
}
public Integer getVisibility() {
return visibility;
}
public void setVisibility(Integer visibility) {
this.visibility = visibility;
}
public Wind getWind() {
return wind;
}
public void setWind(Wind wind) {
this.wind = wind;
}
public Clouds getClouds() {
return clouds;
}
public void setClouds(Clouds clouds) {
this.clouds = clouds;
}
public Integer getDt() {
return dt;
}
public void setDt(Integer dt) {
this.dt = dt;
}
public Sys getSys() {
return sys;
}
public void setSys(Sys sys) {
this.sys = sys;
}
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Integer getCod() {
return cod;
}
public void setCod(Integer cod) {
this.cod = cod;
}
公共类天气{
@序列化名称(“协调”)
@暴露
私人合作社;
@序列化名称(“天气”)
@暴露
私有列表天气=空;
@序列化名称(“基”)
@暴露
私有字符串基;
@序列化名称(“主”)
@暴露
私人主楼;
@序列化名称(“可见性”)
@暴露
私有整数可见性;
@序列化名称(“风”)
@暴露
私人风;
@序列化名称(“云”)
@暴露
私密的云朵;
@序列化名称(“dt”)
@暴露
私有整数dt;
@序列化名称(“sys”)
@暴露
私有系统;
@序列化名称(“id”)
@暴露
私有整数id;
@序列化名称(“名称”)
@暴露
私有字符串名称;
@序列化名称(“cod”)
@暴露
私有整数cod;
公共合作社{
返回坐标;
}
公共无效设置坐标(坐标坐标坐标){
this.coord=coord;
}
公共列表getWeather(){
回归天气;
}
公众天气(列出天气){
这个天气=天气;
}
公共字符串getBase(){
返回基地;
}
公共无效收进框(字符串基){
this.base=base;
}
公共Main getMain(){
回水总管;
}
公共无效设置主(主){
this.main=main;
}
公共整数getVisibility(){
返回能见度;
}
公共void集合可见性(整数可见性){
这个.可见性=可见性;
}
公共风{
回风;
}
公共空间风(风){
风=风;
}
公共云getClouds(){
回归云;
}
公共云(云){
云=云;
}
公共整数getDt(){
返回dt;
}
公共void setDt(整数dt){
这1.dt=dt;
}
公共系统getSys(){
返回系统;
}
公共无效设置系统(Sys Sys){
this.sys=sys;
}
公共整数getId(){
返回id;
}
公共无效集合id(整数id){
this.id=id;
}
公共字符串getName(){
返回名称;
}
公共void集合名(字符串名){
this.name=名称;
}
公共整数getCod(){
返回cod;
}
公共void setCod(整数cod){
this.cod=cod;
}
}
但是Url没有按预期执行。有人能帮我吗。你能发布你的天气分类代码吗?你能告诉我们你想要执行什么类型的Url吗?Url是Json响应这是实际的Url。在印度孟买,我必须动态地给出我自己的城市