Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How add CardItemView dinamically #48

Closed
Bekakk opened this issue Dec 21, 2016 · 21 comments
Closed

How add CardItemView dinamically #48

Bekakk opened this issue Dec 21, 2016 · 21 comments

Comments

@Bekakk
Copy link

Bekakk commented Dec 21, 2016

Hi
I'm using your library.I have one question.Is it a possible to add dinamically CardItemView view in CardSlidePanel.In this example you use static array,but i have json and different size array.
I tried to remove some elements in you arrayList ,but i have IndexOf exceplion

@xmuSistone
Copy link
Owner

Yeah, it is possible to add CardItemView dinamically. Serveral month ago, CardSlidePanel has a public function called appendData(dataList). It is like this:

 /**
     * add new cardlist
     * this function is not tested
     */
    public void appendData(List<CardDataItem> appendList) {
        dataList.addAll(appendList);

        int currentIndex = isShowing;
        int num = viewList.size();
        for (int i = 0; i < num; i++) {
            CardItemView itemView = viewList.get(i);
            itemView.setVisibility(View.VISIBLE);
            itemView.fillData(dataList.get(currentIndex++));
        }
    }

@Bekakk
Copy link
Author

Bekakk commented Dec 23, 2016

yep you are right,but i have indexof exception.This is my xml code

` <com.stone.card.CardSlidePanel
android:id="@+id/image_slide_panel"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerInParent="true">

    <com.stone.card.CardItemView
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />

    <com.stone.card.CardItemView
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />

    <com.stone.card.CardItemView
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />

    <com.stone.card.CardItemView
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />



</com.stone.card.CardSlidePanel>`

and my array has two elements

` private String imagePaths[] = {"assets://wall01.jpg",
"assets://wall02.jpg"}; // 24个图片资源名称

private String names[] = {"郭富城", "刘德华"}; // 24个人名`

` private void prepareDataList() {
int num = imagePaths.length;
for (int i = 0; i < num; i++) {
CardDataItem dataItem = new CardDataItem();
dataItem.userName = names[i];
dataItem.imagePath = imagePaths[i];
dataItem.likeNum = (int) (Math.random() * 10);
dataItem.imageNum = (int) (Math.random() * 6);
dataList.add(dataItem);
}

}`

can you tell me how i can solve my problem? I have error in this snippet

` public void fillData(List dataList) {
this.dataList = dataList;

    int num = viewList.size();
    for (int i = 0; i < num; i++) {
        CardItemView itemView = viewList.get(i);
        itemView.fillData(dataList.get(i));
        itemView.setVisibility(View.VISIBLE);
    }

    if (null != cardSwitchListener) {
        cardSwitchListener.onShow(0);
    }
}

is it a possible to add CardSlidePanel View inside`CardSlidePanel in Xml file.I mean programmatically
thanks

@xmuSistone
Copy link
Owner

Since the logcat has told you everything about the error line, please fix it by yourself.

@Bekakk
Copy link
Author

Bekakk commented Dec 23, 2016

I'll fix.Is it a possible to add CardSlidePanel view iniside CardSlidePanel programmatically? I think problem is that i must have same amount of elements in both sides.(in Arraylist and xml file,CardSlidePanel )

@xmuSistone
Copy link
Owner

Not really. In the xml file, CardSlidePanel needs 4 CardItemView which has nothing to do with your datalist's size.
If your dataList size is below 4, you can set the bottom cards setVisibility(View.INVISIBLE). Do not modify the count of CardItemView....

@Bekakk
Copy link
Author

Bekakk commented Dec 23, 2016

thanks your attention .Can you help me and show me code snippet if array has bellow 4 elements.thanks

@xmuSistone
Copy link
Owner

No. You can adjust your code by yourself. Logcat has told you everything.

@Bekakk
Copy link
Author

Bekakk commented Dec 23, 2016

:) thanks. i try it but i think it's impossibile

@xmuSistone
Copy link
Owner

Yeah. If problems still exists later, you can come to this issue again.

@Bekakk
Copy link
Author

Bekakk commented Dec 23, 2016

I fixed indexof exception but maybe you library not working correct if array size is less 4

@xmuSistone
Copy link
Owner

what does logcat say?

@Bekakk
Copy link
Author

Bekakk commented Dec 23, 2016

I can share CardSlidePanel java source

@xmuSistone
Copy link
Owner

show me the log

@Bekakk
Copy link
Author

Bekakk commented Dec 23, 2016

look.Array's size is 2.First time everything is perfect but i have like this result when swipe finished
I have recorded video
https://www.dropbox.com/s/r8pkrt1usqvupfg/device-2016-12-23-123150.mp4?dl=0

@xmuSistone
Copy link
Owner

show me the error log!!

@Bekakk
Copy link
Author

Bekakk commented Dec 23, 2016

maybe you did not understand me.I have not error.In log everything is okey ,but in my option main logic not working correct if array's length is less then 4
I can share java code

@Bekakk
Copy link
Author

Bekakk commented Dec 23, 2016

any suggestion?

@xmuSistone
Copy link
Owner

what's your email address? simply i send you the java code

@Bekakk
Copy link
Author

Bekakk commented Dec 23, 2016

@xmuSistone
Copy link
Owner

java code has sent to your email.

@TechnoStark
Copy link

This issue is not closed. Problem is still there when you have less than 4 items to be displayed.
Working only when you have items more than 4.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants