在下面的代码中,在语句中显示“返回视图==对象;”

时间:2019-05-29 14:37:25

标签: android-viewpager picasso

先生 我是android编程的新手。我尝试使用ViewPager使用毕加索显示多个侧面滚动图像。

从Youtube Video复制给定的代码以使用View Pager。但是在以下函数中,语句返回视图==对象;对象将错误显示为未定义符号。

public boolean isViewFromObject(@NonNull View view, @NonNull Object o) {
        return view == Object;
    }

下面提供了诸如Mainactivity Java,ViewAdpater类和XMl之类的整个代码

ViewPagerAdapter类

package com.example.imageapp;

import android.content.ComponentName;
import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v4.view.PagerAdapter;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.squareup.picasso.Picasso;

public class ViewPagerAdapter extends PagerAdapter {
    private Context context;
    private String[] imageUrls;
    ViewPagerAdapter(Context context, String[] imageUrls){
        this.context=context;
        this.imageUrls=imageUrls;
    }
    @Override
    public int getCount() {
        return imageUrls.length;
    }

    @Override
    public boolean isViewFromObject(@NonNull View view, @NonNull Object o) {
        return view == Object;
    }

    @NonNull
    @Override
    public Object instantiateItem(@NonNull ViewGroup container, int position) {
        ImageView imageView = new ImageView(context);
        Picasso. get()
                .load(imageUrls[position])
                .fit()
                .centerCrop()
                .into(imageView);
        container.addView(imageView);
        return imageView;
    }

    @Override
    public void destroyItem(@NonNull ViewGroup container, int position, @NonNull Object object) {
       container.removeView((View) object);
    }
}

Main Activity.java

package com.example.imageapp;

import android.content.Context;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLConnection;

import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.AsyncTask;
import android.os.Bundle;
import android.widget.ImageView;
import android.widget.Toast;
import com.bumptech.glide.annotation.GlideModule;
import com.bumptech.glide.module.AppGlideModule;
import com.bumptech.glide.Glide;
import com.squareup.picasso.Callback;
import com.squareup.picasso.Picasso;

import static android.widget.Toast.LENGTH_SHORT;

public class MainActivity extends AppCompatActivity {
private String[] imageUrls = new String[]{
        "http://www.geocities.ws/mariyanaatham/2019/may/1.png",
        "http://www.geocities.ws/mariyanaatham/2019/may/2.png"
};
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        ViewPager viewPager = findViewById(R.id.view_pager);
        ViewPagerAdapter adapter= new ViewPagerAdapter(this,imageUrls);
        viewPager.setAdapter(adapter);
        /*String MY_URL_STRING ="http://www.geocities.ws/mariyanaatham/2019/may/1.png";
        ImageView iv = (ImageView) findViewById(R.id.iv);
        Context context = getApplicationContext();
        Picasso.get()
                .load(MY_URL_STRING)
                .placeholder(R.drawable.mary)
                .into(iv);*/
    }


}

Activity_Main XML

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">

    <android.support.v4.view.ViewPager
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tool="http://schemas.android.com/tools"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:id="@+id/view_pager"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

    </android.support.v4.view.ViewPager>
    </android.support.constraint.ConstraintLayout>

我的意图是显示从URL strong text

加载的多个侧面可滚动图像

0 个答案:

没有答案