ImageSlider Галерея изображений Drawabler - PullRequest
0 голосов
/ 02 мая 2020

Я пытаюсь создать галерею слайдера изображений в своем приложении, чтобы пользователи могли перемещаться по галерее фотографий пальцем влево и вправо. У меня есть массив данных, которые сериализуются и передаются моему новому намерению, которое показывает содержание всех моих поставщиков для нового намерения. Я не могу передать изображения держателю изображения в моем XML.

Вот мой ViewHolder,

    package android.com.example.weddingappfinale;

import android.os.Parcel;
import android.os.Parcelable;

import java.io.Serializable;

public class MuaView implements Serializable {
    private int mImageResource;
    private String mTitle;
    private String mDescription;
    private String mServices1;
    private String mServices2;
    private int mImageSlider;
    private String mContact;
    private String mAddress;

    public MuaView(int imageResource, String title, String description, String services1, String services2, int imageslider, String contact, String address) {
        mImageResource = imageResource;
        mTitle = title;
        mDescription = description;
        mServices1 = services1;
        mServices2 = services2;
        mImageSlider = imageslider;
        mContact = contact;
        mAddress = address;

    }

    protected MuaView(Parcel in) {
        mImageResource = in.readInt();
        mTitle = in.readString();
    }

    public MuaView(int mua_image, String shima_matin_bridal_services) {
    }

    public int getImageResource() {
        return mImageResource;
    }

    public String getmTitle() {
        return mTitle;
    }

    public String getmDescription() {
        return mDescription;
    }

    public String getmServices1() {
        return mServices1;
    }

    public String getmServices2() {
        return mServices2;
    }

    public int getmImageSlider() {
        return mImageSlider;
    }

    public String getmContact() {
        return mContact;
    }

    public String getmAddress() {
        return mAddress;
    }

}

Вот мой Activity, где создается ArrayList,

    package android.com.example.weddingappfinale;

import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.inputmethod.EditorInfo;

import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.SearchView;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import java.util.ArrayList;

import Adapters.MuaAdapter;
import CustomerActivities.MuaCustomerActivity;

public class MuaActivity extends AppCompatActivity {

    private RecyclerView mRecyclerView;
    private MuaAdapter mAdapter;
    private RecyclerView.LayoutManager mLayoutManager;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.mua_list);

        getSupportActionBar().setTitle("Make Up Artists");
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);

        final ArrayList<MuaView> muaView = new ArrayList<>();
        muaView.add(new MuaView(R.drawable.mua_image, "Shima Matin Bridal", "Shima Matin started in 2012","Bridal Makeup","",R.drawable.gift_image,"81806627","36 Marsiling Drive #13-407 Block A"));
        muaView.add(new MuaView(R.drawable.photography_image, "ABCD Pte Ltd", "ABCD Pte Ltd founded in 2019, a new kid in the block","Bridal Clothes","Bridal Accessories",R.drawable.gift_image,"98262806","684A Choa Chua Kang Crescent #06-310"));
        muaView.add(new MuaView(R.drawable.placeholder,"Wooha Pte Ltd","Started in 2010","Bridal Makeup","Bridal Clothes",R.drawable.gift_image,"91923182","Singapore 73923"));


        // ArrayList

        mRecyclerView = findViewById(R.id.recycler_view_list);
        mRecyclerView.setHasFixedSize(true);
        mLayoutManager = new LinearLayoutManager(this);
        mAdapter = new MuaAdapter(muaView);

        mRecyclerView.setLayoutManager(mLayoutManager);
        mRecyclerView.setAdapter(mAdapter);

        // Item Click listener for CardView and Parcel CardView to new Intent

        mAdapter.setOnItemClickListener(new MuaAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(int position) {
                Intent intent = new Intent(MuaActivity.this, MuaCustomerActivity.class);
                intent.putExtra("Customer's Details", muaView.get(position));
                startActivity(intent);
            }

        });

    }

    // Filter/Search Bar

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        MenuInflater inflater = getMenuInflater();
        inflater.inflate(R.menu.search, menu);

        MenuItem searchItem = menu.findItem(R.id.action_search);
        SearchView searchView = (SearchView) searchItem.getActionView();

        searchView.setImeOptions(EditorInfo.IME_ACTION_DONE);

        searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
            @Override
            public boolean onQueryTextSubmit(String query) {
                return false;
            }

            @Override
            public boolean onQueryTextChange(String newText) {
                mAdapter.getFilter().filter(newText);
                return false;
            }
        });
        return true;
    }
}

Вот где создается новое намерение,

    package CustomerActivities;

import android.com.example.weddingappfinale.MuaView;
import android.com.example.weddingappfinale.R;
import android.content.Intent;
import android.os.Bundle;
import android.widget.ImageButton;
import android.widget.TextView;

import androidx.appcompat.app.AppCompatActivity;

import com.denzcoskun.imageslider.ImageSlider;
import com.denzcoskun.imageslider.models.SlideModel;

import org.w3c.dom.Text;

import java.util.ArrayList;
import java.util.List;

public class MuaCustomerActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_customer);
        Intent intent = getIntent();
        MuaView muaView = (MuaView) intent.getSerializableExtra("Customer's Details");

        int imageRes = muaView.getImageResource();
        String title = muaView.getmTitle();
        String description = muaView.getmDescription();
        String services1 = muaView.getmServices1();
        String services2 = muaView.getmServices2();
        String contact = muaView.getmContact();
        String address = muaView.getmAddress();

        ImageButton imageButton = findViewById(R.id.image_customer);
        imageButton.setImageResource(imageRes);

        TextView textView = findViewById(R.id.descriptionVendor);
        textView.setText(description);

        TextView textView1 = findViewById(R.id.title_customer);
        textView1.setText(title);

        TextView textView2 = findViewById(R.id.services1);
        textView2.setText(services1);

        TextView textView3 = findViewById(R.id.services2);
        textView3.setText(services2);

        TextView textView4 = findViewById(R.id.contactVendor);
        textView4.setText(contact);

        TextView textView5 = findViewById(R.id.addressvendor);
        textView5.setText(address);

        ImageSlider imageSlider = findViewById(R.id.imageslider);
        List<SlideModel> slideModels = new ArrayList<>();
        slideModels.add(new SlideModel(R.drawable.catering_image));
        slideModels.add(new SlideModel(R.drawable.entertainment_image));
        imageSlider.setImageList(slideModels, true);
    }
}

Вот макет XML,

    <?xml version="1.0" encoding="utf-8"?>
<androidx.core.widget.NestedScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <RelativeLayout
        android:layout_width="wrap_content"
        android:layout_height="match_parent">

        <ImageButton
            android:id="@+id/image_customer"
            android:layout_width="match_parent"
            android:layout_height="200dp"
            android:layout_margin="4dp"
            android:adjustViewBounds="true"
            android:background="@drawable/ic_launcher_background"
            android:scaleType="centerCrop" />

        <TextView
            android:id="@+id/title_customer"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@id/image_customer"
            android:layout_centerHorizontal="true"
            android:layout_margin="4dp"
            android:fontFamily="@font/open_sans_semibold"
            android:text="" />

        <TextView
            android:id="@+id/description"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Description"
            android:layout_below="@id/title_customer"
            android:layout_centerHorizontal="true"
            android:fontFamily="@font/open_sans_extrabold"/>

        <TextView
            android:id="@+id/descriptionVendor"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Description of Vendors"
            android:layout_below="@id/description"
            android:layout_centerHorizontal="true"/>

        <TextView
            android:id="@+id/services"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@id/descriptionVendor"
            android:layout_centerHorizontal="true"
            android:layout_marginTop="8dp"
            android:fontFamily="@font/open_sans_extrabold"
            android:text="@string/services" />

        <TextView
            android:id="@+id/services1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@id/services"
            android:layout_centerHorizontal="true"
            android:layout_toEndOf="@id/services"
            android:layout_toRightOf="@id/services"
            android:text="Services1" />

        <TextView
            android:id="@+id/services2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@id/services1"
            android:layout_centerHorizontal="true"
            android:layout_marginBottom="4dp"
            android:layout_toRightOf="@id/services"
            android:text="Services2" />

        <TextView
            android:id="@+id/gallery"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@id/services2"
            android:layout_centerHorizontal="true"
            android:layout_marginTop="8dp"
            android:fontFamily="@font/open_sans_extrabold"
            android:text="@string/gallery" />

        <com.denzcoskun.imageslider.ImageSlider
            android:id="@+id/imageslider"
            android:layout_width="wrap_content"
            android:layout_height="200dp"
            android:layout_below="@id/gallery"
            android:layout_centerHorizontal="true"
            android:layout_margin="4dp"
            app:delay="0"
            app:placeholder="@drawable/mua_image" />

        <TextView
            android:id="@+id/contact"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@id/imageslider"
            android:layout_centerHorizontal="true"
            android:layout_marginTop="8dp"
            android:fontFamily="@font/open_sans_extrabold"
            android:text="Contact"/>

        <TextView
            android:id="@+id/contactVendor"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@id/contact"
            android:layout_centerHorizontal="true"
            android:text="ContactVendor" />

        <TextView
            android:id="@+id/address"
            android:layout_below="@id/contactVendor"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Address"
            android:layout_centerHorizontal="true"
            android:fontFamily="@font/open_sans_extrabold"/>

        <TextView
            android:id="@+id/addressvendor"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@id/address"
            android:text="AddressVendor"
            android:layout_centerHorizontal="true"/>


    </RelativeLayout>
</androidx.core.widget.NestedScrollView>
...