-
Notifications
You must be signed in to change notification settings - Fork 18
ProfileListView
Steve Hannah edited this page Jul 6, 2021
·
2 revisions
<profileListView>
• javadoc
Since this component extends EntityListView, it supports all attributes therein.
It also supports these attributes:
- avatarSize
-
The diameter of the avatar in scalar units. Default pixels.
- ACCOUNT_LIST_ROW_ACTIONS
-
Actions that will be added to a menu on each row of the list.
- ACCOUNT_LIST_ROW_SELECTED
-
Triggered when user clicks on a row.
ProfileListViewSample.xml
<?xml version="1.0"?>
<y xsi:noNamespaceSchemaLocation="ProfileListViewSample.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<title>ProfileListView</title>
<import>
import com.codename1.rad.sampler.providers.*;
import com.codename1.rad.sampler.models.*;
</import>
<profileListView provider="SampleListProvider.class"/>
<var name="profiles" type="EntityList"/>
<script>
/* NOTE: Creating the model here only for simplicity of sample.
in real app you should load entity list from view model or lookup.
*/
profiles = new EntityList();
UserProfile george = new UserProfileImpl();
george.setName("George");
george.setPhotoUrl("https://weblite.ca/cn1tests/radchat/george.jpg");
profiles.add(george);
UserProfile kramer = new UserProfileImpl();
kramer.setName("Kramer");
kramer.setPhotoUrl("https://weblite.ca/cn1tests/radchat/kramer.jpg");
profiles.add(kramer);
UserProfile jerry = new UserProfileImpl();
jerry.setName("Jerry");
profiles.add(jerry);
</script>
<profileListView view-model="profiles"/>
<profileListView view-model="profiles" avatarSize="25vw"/>
</y>
The above example creates 3 different <profileListView>
instances. The first one uses the provider
attribute to get its rows from the "SampleListProvider".
For the second and third list I manually constructed an EntityList to use as the model in a <script>
tag.
Note
|
It is generally bad practice to create models inside <script> tags like this. This was done for clarity of the example. In your apps it would be better to construct or load models in the controller and pass it to the view either in the view model, or as a lookup.
|
For completeness, the following is the implementation of the SampleListProvider
.
SampleListProvider.java
package com.codename1.rad.sampler.providers;
import com.codename1.io.Log;
import com.codename1.rad.io.ResultParser;
import com.codename1.rad.models.AbstractEntityListProvider;
import com.codename1.rad.models.EntityList;
import com.codename1.rad.models.EntityListProvider;
import com.codename1.rad.sampler.models.UserProfile;
import com.codename1.rad.sampler.models.UserProfileImpl;
import com.codename1.ui.CN;
import java.io.IOException;
import static com.codename1.ui.CN.scheduleBackgroundTask;
public class SampleListProvider extends AbstractEntityListProvider {
@Override
public Request getEntities(Request request) {
EntityList out = new EntityList();
{
UserProfile profile = new UserProfileImpl();
profile.setName("Steve Hannah");
profile.setEmail("steve@example.com");
profile.setPhotoUrl("https://www.codenameone.com/img/steve.jpg");
out.add(profile);
}
{
UserProfile profile = new UserProfileImpl();
profile.setName("Shai Almog");
profile.setEmail("shai@example.com");
profile.setPhotoUrl("https://www.codenameone.com/img/shai.jpg");
out.add(profile);
}
{
UserProfile profile = new UserProfileImpl();
profile.setName("Chen Fishbein");
profile.setEmail("chen@example.com");
profile.setPhotoUrl("https://www.codenameone.com/img/chen.jpg");
out.add(profile);
}
request.complete(out);
return request;
}
}
Important
|
In order for this example to work, an instance of SampleListProvider also needed to be added as a lookup in the controller. E.g. `addLookup(new SampleListProvider()); |
Screenshot