java - Viewflipper 图像在使用动态数据时不会改变
问题描述
我正在制作广告横幅,我想在横幅布局中 4 秒后翻转图像,因此我正在使用 viewflipper。我想显示从 Web 服务获取的图像,因此我正在解析来自 Web 服务的图像并创建它的列表,但是当使用 for 循环将该列表项传递给 viewflipper 时,它只显示一个图像并且列表有两个项目。谁能帮我弄清楚我的错误。
查看脚蹼方法..
public void flipperImages(String image){
ImageView imageView = new ImageView(this);
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
imageView.setLayoutParams(params);
Log.e("image_product", image);
if (image.equals("0")) {
imageView.setBackgroundResource(R.drawable.placeholder_rec);
} else {
Picasso.with(this).load(image).error(R.drawable.placeholder_rec).placeholder(R.drawable.placeholder_rec).into(imageView);
}
v_flipper.addView(imageView);
v_flipper.setFlipInterval(4000);
v_flipper.setAutoStart(true);
v_flipper.setInAnimation(this, android.R.anim.slide_in_left);
v_flipper.setOutAnimation(this, android.R.anim.slide_out_right);
}
Api 调用和 FlipperImages() 调用...
private void categoryListApi() {
if (NetworkUtil.isNetworkAvailable(this)) {
loader.setVisibility(View.VISIBLE);
Api api = ApiClient.getClient().create( Api.class );
Call<ResponseBody> call = api.getCatList("1");
call.enqueue( new Callback<ResponseBody>() {
@Override
public void onResponse(Call<ResponseBody> call, Response<ResponseBody> response) {
try {
loader.setVisibility(View.GONE);
String JSON_STRING = response.body().string();
JSONObject jsonRootObject = new JSONObject( JSON_STRING );
String status = jsonRootObject.getString( "status" );
String message = jsonRootObject.getString( "message" );
if (status.equals( "1" ))
{
JSONArray jsonArrayBanner = jsonRootObject.getJSONArray( "banner" );
for (int i=0; i<jsonArrayBanner.length(); i++)
{
JSONObject objectData = jsonArrayBanner.getJSONObject(i);
String bannerUrl = objectData.getString( "img" );
bannerList.add( bannerUrl );
}
Log.e("banner", bannerList.toString());
for (int i=0; i<bannerList.size(); i++)
{
flipperImages(bannerList.get(i));
}
} else {
loader.setVisibility(View.GONE);
Toast.makeText(getApplicationContext(), message, Toast.LENGTH_SHORT).show();
}
} catch (Exception e) {
Log.e( "ErrorProfile" , e.getMessage());
loader.setVisibility(View.GONE);
popUpDialog();
}
}
@Override
public void onFailure(Call<ResponseBody> call, Throwable t) {
loader.setVisibility(View.GONE);
//Toast.makeText( getApplicationContext(), "Failed " + t, Toast.LENGTH_LONG ).show();
}
} );
}
else {
popUpDialogInternet();
}
}
解决方案
推荐阅读
- c++ - C ++如何将std :: array的内容复制到另一个?
- sql - 另一种编写查询以在没有长列表的情况下计算一行中的值的方法
- python - Python SpeechRecognition 不听完整的音频?
- unit-testing - Companion 对象内的模拟扩展功能
- javascript - 如果不使用 vue-cli 或构建工具,如何丑化 VueJS 代码?
- javascript - Jest toHaveBeenNthCalled 字符串比较中的转义字符
- react-dnd - 你能以编程方式取消拖动吗
- javascript - Nodejs - 错误消息,第n次失败输出n条失败消息
- javascript - 将函数传递给 Material UI useStyles
- typescript - 区分泛型类中泛型值的过滤数组项