Populating A ListView With Objects From Parse.com Android
I'm trying to fill a ListView with objects from my database at Parse.com, but I'm am having trouble because the ListView does not accept objects directly. I've tried making an arra
Solution 1:
you can use BaseAdapter class for custom listview. here is the code for that.
List<ParseObject> parse = new ArrayList<ParseObject>();
public class CustomChannelListAdapter extends BaseAdapter {
private Context context;
public CustomChannelListAdapter(Context context) {
super();
this.context = context;
}
@Override
public int getCount() {
if (parse != null) {
return parse.size();
}
return 0;
}
@Override
public Channel getItem(int position) {
// TODO Auto-generated method stub
return parse.get(position);
}
@Override
public long getItemId(int position) {
// TODO Auto-generated method stub
return 0;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View view = convertView;
TextView tittle = null;
TextView desc = null;
TextView nowPlaying = null;
if (view == null) {
LayoutInflater inflater = ((Activity) context)
.getLayoutInflater();
view = inflater.inflate(R.layout.video_listrow, parent, false);
} else {
view = convertView;
}
tittle = (TextView) view.findViewById(R.id.title);
desc = (TextView) view.findViewById(R.id.Descp);
nowPlaying = (TextView) view.findViewById(R.id.NowplayingId);
if (parse!= null) {
if (parse.get(position).getName() != null) {
tittle.setText(parse.get(position).getName()
.toString());
} else {
tittle.setText("----------------------");
}
if (parse.get(position).getDesc() != null) {
desc.setText(parse.get(position).getDesc()
.toString());
} else {
desc.setText("------------------------");
}
}
return view;
}
}
video_listrow.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="400dp"
android:layout_height="75dp"
android:background="@drawable/videolist_selector"
android:orientation="horizontal"
android:paddingLeft="5dp"
android:paddingRight="5dp" >
<!-- Title Of Song -->
<TextView
android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingTop="5dp"
android:textColor="@color/orange"
android:textSize="18dip"
android:textStyle="bold"
android:typeface="sans"
android:ellipsize="marquee"
android:freezesText="true"
android:marqueeRepeatLimit="marquee_forever"
android:paddingLeft="5dip"
android:scrollHorizontally="true"
android:singleLine="true"
android:text="Tittle Not Found " />
<!-- Artist Name -->
<TextView
android:id="@+id/Descp"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@id/title"
android:layout_marginTop="1dip"
android:layout_toRightOf="@+id/thumbnail"
android:paddingTop="5dp"
android:textColor="@color/white"
android:textSize="12dip"
android:textStyle="bold"
android:typeface="sans"
android:ellipsize="marquee"
android:freezesText="true"
android:marqueeRepeatLimit="marquee_forever"
android:paddingLeft="5dip"
android:scrollHorizontally="true"
android:singleLine="true"
android:text="Description Not Found"
/>
<!-- Rightend Duration -->
<!--
<TextView
android:id="@+id/duration"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignTop="@id/title"
android:gravity="right"
android:text="5:45"
android:layout_marginRight="5dip"
android:textSize="10dip"
android:textColor="#10bcc9"
android:textStyle="bold"/>
-->
<!-- Rightend Arrow -->
<!--
<ImageView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/arrow"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"/>
-->
<TextView
android:id="@+id/NowplayingId"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_marginBottom="5dp"
android:layout_marginRight="4dp"
android:text="Now playing..."
android:textColor="@color/red"
android:textSize="12dp" />
</RelativeLayout>
In your activity code
ListView videoList = (ListView) findviewByid(_);
CustomChannelListAdapter channelAdapter = new CustomChannelListAdapter(PlasmaView.this);
videoList.setAdapter(channelAdapter);
Post a Comment for "Populating A ListView With Objects From Parse.com Android"