Tuesday, May 19, 2015

CardListView Example Android

CardListView Example Output :

Output



Step 1 :

Add dependencies in "build.gradle" file in Android Studio


dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    compile 'com.android.support:appcompat-v7:22.1.0'
    compile 'com.github.gabrielemariotti.cards:cardslib-core:2.0.1'}


for here i am using https://github.com/gabrielemariotti/cardslib library.


Project Structure :

Project Structure
Note : here i can import new module => "cardslib-core-2.0.1 aar" file from : http://mvnrepository.com/artifact/com.github.gabrielemariotti.cards/cardslib-core/2.0.1


Step 2 :


activity_main

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:orientation="vertical"
 xmlns:card="http://schemas.android.com/apk/res-auto" > 

<it.gmariotti.cardslib.library.view.CardListView 
android:layout_marginTop="10dp" 
android:id="@+id/cardListView" 
android:layout_width="match_parent" 
android:layout_height="match_parent" card:list_card_layout_resourceID="@layout/list_card_thumbnail_layout" style="@style/list_card.thumbnail"/> 

</LinearLayout>

Step 3 :

MainActivity.java

import android.app.Activity; 
import android.os.Bundle; 
import java.util.ArrayList;

import it.gmariotti.cardslib.library.internal.Card;
import it.gmariotti.cardslib.library.internal.CardArrayAdapter;
import it.gmariotti.cardslib.library.internal.CardHeader;
import it.gmariotti.cardslib.library.internal.CardThumbnail;
import it.gmariotti.cardslib.library.view.CardListView;

public class MainActivity extends Activity {

 @Override protected void onCreate(Bundle savedInstanceState) {

 super.onCreate(savedInstanceState);
 setContentView(R.layout.activity_main);
 int listImages[] = new int[]{R.drawable.logo_apple, 
 R.drawable.logo_shell, R.drawable.logo_volkswagen, R.drawable.logo_ea};

 ArrayList<Card> cards = new ArrayList<Card>();
 for (int i = 0; i<4; i++) {
 // Create a Card 
 Card card = new Card(this);
 // Create a CardHeader 
 CardHeader header = new CardHeader(this);
 // Add Header to card 
 header.setTitle("Logo : " + i);
 card.setTitle("Set Your Text Here");
 card.addCardHeader(header);
 CardThumbnail thumb = new CardThumbnail(this);
 thumb.setDrawableResource(listImages[i]);
 card.addCardThumbnail(thumb);
 cards.add(card);
 }
 CardArrayAdapter mCardArrayAdapter = new CardArrayAdapter(this, cards);
 CardListView listView = (CardListView) this.findViewById(R.id.cardListView);
 if (listView != null) {
 listView.setAdapter(mCardArrayAdapter);
 }
 }
}

Step 4 :

@drawable
logo_apple
logo_shell
logo_volkswagen
logo_ea

Step 5 :

Run App and Enjoy it......
Download This Project From below link :
https://drive.google.com/file/d/0By1zg6cvLTQ9cEdyRDRDX1RoVms/view?usp=sharing

1 comment: