Skip to content

Commit

Permalink
Improved cardwithlist doc and updated the examples
Browse files Browse the repository at this point in the history
  • Loading branch information
gabrielemariotti committed Jun 17, 2014
1 parent 048f2db commit 5f9759a
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,8 @@ public void onConnectionError(Throwable t) {
private void initCard() {

//Weather Card
card= new WeatherCard(getActivity());
card= new WeatherCard(getActivity());
card.init();

//Set card in the cardView
CardView cardView = (CardView) getActivity().findViewById(R.id.carddemo_weathercard);
Expand All @@ -135,6 +136,7 @@ private void initCard() {

//May know card
GoogleKnowwithList card2= new GoogleKnowwithList(getActivity());
card2.init();

//Set card in the cardView
CardView cardView2 = (CardView) getActivity().findViewById(R.id.carddemo_mayknowcard);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@
*/
public class CardWithListFragment extends BaseFragment {

GoogleNowWeatherCard card;
GoogleNowStockCardwithList card2;

@Override
public int getTitleResourceId() {
return R.string.carddemo_title_carwithlist_card;
Expand Down Expand Up @@ -65,20 +68,30 @@ public void onActivityCreated(Bundle savedInstanceState) {
private void initCard() {

//Create a Card
GoogleNowWeatherCard card= new GoogleNowWeatherCard(getActivity());
card= new GoogleNowWeatherCard(getActivity());
card.init();

//Set card in the cardView
CardView cardView = (CardView) getActivity().findViewById(R.id.carddemo_weathercard);
cardView.setCard(card);


//Card
GoogleNowStockCardwithList card2 = new GoogleNowStockCardwithList(getActivity());
card2 = new GoogleNowStockCardwithList(getActivity());
card2.init();

//Set card in the cardView
CardView cardView2 = (CardView) getActivity().findViewById(R.id.carddemo_stockcard);
cardView2.setCard(card2);

}

@Override
public void onPause() {
super.onPause();
if (card != null)
card.unregisterDataSetObserver();
if (card2 != null)
card2.unregisterDataSetObserver();
}
}
56 changes: 55 additions & 1 deletion doc/CARDWITHLIST.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ In this page you can find info about:
* [Init the Children](#init-the-children)
* [Define the layout used by items](#define-the-layout-used-by-items)
* [Setup child view](#setup-child-view)
* [Extending the init method](#extending-the-init-method)
* [How to add and remove items dynamically](#how-to-add-and-remove-items-dynamically)
* [How to customize the divider](#how-to-customize-the-divider)
* [Empty View](#empty-view)
* [How to disable the empty view](#how-to-disable-the-empty-view)
Expand Down Expand Up @@ -51,6 +53,14 @@ In this case you have to extend the `CardWithList` (which extends `Card`) and im
}
```

Finally you have to call the `init()` method.

``` java
GoogleNowWeatherCard card = new GoogleNowWeatherCard(context);
card.init();
```


## Init the CardHeader

You have to specify your `CardHeader` using the method `initCardHeader()`.
Expand Down Expand Up @@ -221,6 +231,50 @@ After declaring the layout used by items, you have to setup the elements inside
}
```

## Extending the init method

You can extend your `init` method to set your custom variables.

``` java
@Override
public void init() {
//Insert your code here...
mField = xxx;

//Finally call the super.init();
super.init();
}
```

## How to add and remove items dynamically

You can add and remove items dynamically, using a method inside your `Card` through the `getLinearListAdapter()` method.

``` java
public void updateItems(ArrayList myList) {

//Update the array inside the card
ArrayList<MyObject> objs = new ArrayList<WeatherObject>();
//.....
getLinearListAdapter().addAll(objs);

//use this line if your are using the progress bar
//updateProgressBar(true,true);
}
```

``` java
public void updateItems(String city,int temp) {
WeatherObject w1= new WeatherObject(GoogleNowWeatherCard.this);
w1.city =city;
w1.temperature = temp;
w1.weatherIcon = R.drawable.ic_action_sun;
w1.setObjectId(w1.city);
mLinearListAdapter.add(w1);
}
```


## How to customize the divider

You can customize the divider used by the List.
Expand Down Expand Up @@ -402,4 +456,4 @@ Also you can add other elements inside you layout. In this case you have to set

## Note about CardListView

Currently this kind of `Card` can't be used inside a `CardListView`.
Currently this kind of `Card` is not supported to be used inside a `CardListView`.

0 comments on commit 5f9759a

Please sign in to comment.