このライブラリを使用したことはありませんが、ドキュメントから、通常のリストと同じように処理する必要があると思われます。アダプターでは、ビューを埋める必要があり、notifydatasetchanged() によって更新できます。
https://github.com/gabrielemariotti/cardslib/blob/master/doc/QUICKUSAGE.md
編集: 以下の非常に原始的なサンプルを作成しました。
アクティビティ:
public class MyActivity extends Activity {
private static final int MAX_LENGTH = 20;
private ArrayList<Card> cards = new ArrayList<Card>();
private CardAdapter arrayAdapter;
private HashMap<Integer, String> optionalValues = new HashMap<Integer, String>();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_my);
arrayAdapter = new CardAdapter(getBaseContext(), cards, optionalValues);
for(int i = 0; i < 10; i++) {
Card card = new Card(getBaseContext());
CardHeader header = new CardHeader(getBaseContext());
header.setTitle("ASDF");
card.setInnerLayout(R.layout.card1_layout);
card.addCardHeader(header);
cards.add(card);
}
CardListView listView = (CardListView) findViewById(R.id.card_list);
listView.setAdapter(arrayAdapter);
Button btn = (Button) findViewById(R.id.btn_rand);
btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String rnd = random();
Toast.makeText(getBaseContext(), "Generated for 2nd card: " + rnd, Toast.LENGTH_SHORT).show();
optionalValues.put(1, rnd);
arrayAdapter.notifyDataSetChanged();
}
});
}
public static String random() {
Random generator = new Random();
StringBuilder randomStringBuilder = new StringBuilder();
int randomLength = generator.nextInt(MAX_LENGTH);
char tempChar;
for (int i = 0; i < randomLength; i++){
tempChar = (char) (generator.nextInt(96) + 32);
randomStringBuilder.append(tempChar);
}
return randomStringBuilder.toString();
}}
アダプタ:
public class CardAdapter extends CardArrayAdapter {
private final LayoutInflater mInflater;
private HashMap<Integer, String> opts;
public CardAdapter(Context context, List<Card> cards, HashMap<Integer, String> optionalValues) {
super(context, cards);
this.mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
this.opts = optionalValues;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View v = super.getView(position, convertView, parent);
TextView tv = (TextView) v.findViewById(R.id.text1);
if(position == 1 && opts.get(1) != null) {
tv.setText(opts.get(1));
} else {
//items are recycled so let's get back to default values
tv.setText("default");
}
return v;
}}
主なアクティビティ xml:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
tools:context=".MyActivity">
<Button
android:id="@+id/btn_rand"
android:layout_centerHorizontal="true"
android:text="Randomize 2nd text"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<it.gmariotti.cardslib.library.view.CardListView
android:id="@+id/card_list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="12dp"
android:layout_marginRight="12dp"
android:layout_marginTop="60dp"
/>
カード内部レイアウト (「card1_layout.xml」):
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/carddemo"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="12dp"
android:layout_marginRight="12dp"
android:layout_marginTop="12dp"
android:orientation="vertical">
<TextView
android:id="@+id/text1"
android:text="default"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/text2"
android:text="default2"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>