Je crée une application avec cardlistview .. I mis en œuvre la vue de la liste des cartes en utilisant la bibliothèque de cartes gabrielemariotti gabrielemariotti cardsComment ajouter la mise en page personnalisée dans CardListView pour les cartes gabrielemariotti
Je suis en mesure d'atteindre la vue cardlist et en gonflant la mise en page personnalisée est également réussie. Bien que je ne peux pas définir les valeurs à textviews dans la mise en page personnalisée texview comme il obtient des valeurs nulles ..
Ma liste de carte XML est:
<it.gmariotti.cardslib.library.view.CardListView
android:id="@+id/myList"
android:layout_width="match_parent"
android:layout_height="match_parent"
card:list_card_layout_resourceID="@layout/news_card"/>
news_card.xml:
<?xml version="1.0" encoding="utf-8"?>
<it.gmariotti.cardslib.library.view.CardView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:card="http://schemas.android.com/apk/res-auto"
android:id="@+id/list_cardId"
android:layout_width="match_parent"
android:layout_height="wrap_content"
card:card_layout_resourceID="@layout/card_thumbnail_layout"
/>
news_card_layout .xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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"
android:orientation="vertical"
android:padding="10dp" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
</RelativeLayout>
<TextView
android:text="News"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/myNews"
android:textSize="18sp"
tools:text="news" />
<TextView
android:text="Date"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/mydate"
android:gravity="right"
tools:text="date" />
</LinearLayout>
Mon code d'activité pour créer les cartes ":
ArrayList<Card> cards = new ArrayList<Card>();
for (int i = 0; i<5; i++) {
// Create a Card
Card card1 = new Card(this.getActivity(),R.layout.news_card_layout);
CardHeader header1 = new CardHeader(this.getActivity());
// Add Header to card
header1.setTitle("hi");
card1.addCardHeader(header1);
CardThumbnail thumb = new CardThumbnail(this.getActivity());
thumb.setUrlResource("https://lh5.googleusercontent.com/-N8bz9q4Kz0I/AAAAAAAAAAI/AAAAAAAAAAs/Icl2bQMyK7c/s265-c-k-no/photo.jpg");
card1.addCardThumbnail(thumb);
TextView newsdesc = (TextView)getView().findViewById(R.id.myNews);
newsdesc.setText("hello");
/*TextView mydate = (TextView)getView().findViewById(R.id.mydate);
mydate.setText("2 Seconds ago");*/
cards.add(card1);
card1.setOnClickListener(new Card.OnCardClickListener() {
@Override
public void onClick(Card card, View view) {
Toast.makeText(getActivity(),"Clickable card", Toast.LENGTH_LONG).show();
}
});
}
CardArrayAdapter mCardArrayAdapter = new CardArrayAdapter(this.getActivity(), cards);
CardListView listView = (CardListView) this.getView().findViewById(R.id.myList);
if (listView != null) {
listView.setAdapter(mCardArrayAdapter);
}