Open ben04 opened 9 years ago
Currently you can use only a global layout with the CardListView.
To be clear you can use only one layout with card:list_card_layout_resourceID="@layout/customcard_layout"
.
I will introduce a new feature with 2.x to allow multiple layouts.
Now, you can use different inner layouts with your card in the list.
To be clear it means:
Card card = new Card(context, R.my_inner_layout);
You can find more info here:
https://github.com/gabrielemariotti/cardslib/blob/master/doc/CARDLIST.md#cards-with-different-inner-layouts
However in your case you can also do it:
setupInnerViewElement
to set elements inside a card.The perfect solution would be kind of extra methods like your .setTitle() etc...
In this case you can extend your card and set ui elements in the setupInnerViewElement
using your favorite layout.
MyCard card = new MyCard(context, R.layout.favorite_layout);
public class MyCard extends Card{
public void setSubTitle(String subtitle.....){
mSubtitle = subtitle
}
@Override
public void setupInnerViewElements(ViewGroup parent, View view) {
//Retrieve elements
TextView mSubTitleTv = (TextView)
parent.findViewById(R.id.subtitle);
mSubTitleTv.setText(mSubtitle);
}
}
I want to use one layout, so each card shall have 3 TextViews and 3 Buttons. What I need to do is set the texts of the TextViews and actions of the Buttons individually for every card. However, I managed to add and show cards dynamically, that works perfect now.
I tried to customize my custom card class as you did in your example above, but how do I call these custom functions then? card.setSubTitle("Text") did not work.
Post your code
I found my mistake myself, so that works now too! :-)
Next question: How do I manage the clicks on the three buttons of each card? I'd need either the ID of the card or just the text of the second textview and of course which button was pressed, then I'd know how to handle this..
The way is always the same
@Override
public void setupInnerViewElements(ViewGroup parent, View view) {
myButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View view) {
mymethod(getId(),textView,,,,);
}
});
}
}
The result here is an error in Android Studio:
You have to use a ClickListener on the button, while you are using the onCardClickListener.
Thanks a lot, that works now (though you edited your post, didn't you? :D )
I edited my answer just 2 minutes after writing it.
When I add the cards dynamically to my CardListView it seems to generate two shadows for each card. How can I change this?
Hey,
I'd like to develop an app, where cards get dynamically added, according to the user input on the activity before the one with the cards. Each card should have the same (custom) layout with 3 textviews and 3 buttons. Though, the textviews of each card need to have different content.
Moreover it has to be possible to click the three buttons and get a reaction according to the content of the textviews, so I have to get the ID of the card of the button clicked.
I've been skimming your doc for a few days now and have tried a few simple things like adding new cards with custom layouts and so on. Though I'm not sure if I can achieve my goals with this library and, if so, how to preferably do that.
I guess I should take the CardListView? Shall I take a custom layout (card:list_card_layout_resourceID="@layout/customcard_layout") or setupInnerViewElements? The perfect solution would be kind of extra methods like your .setTitle() etc. to fill those textviews. Is that possible? Or is there an even easier way?
It would be great if you could give me kind of a rough roadmap what's fitted best for my requirements :-)
Greetz Ben