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 = newArrayList<ParseObject>();
publicclassCustomChannelListAdapterextendsBaseAdapter {
private Context context;
publicCustomChannelListAdapter(Context context) {
super();
this.context = context;
}
@OverridepublicintgetCount() {
if (parse != null) {
return parse.size();
}
return0;
}
@Overridepublic Channel getItem(int position) {
// TODO Auto-generated method stubreturn parse.get(position);
}
@OverridepubliclonggetItemId(int position) {
// TODO Auto-generated method stubreturn0;
}
@Overridepublic View getView(int position, View convertView, ViewGroup parent) {
Viewview= convertView;
TextViewtittle=null;
TextViewdesc=null;
TextViewnowPlaying=null;
if (view == null) {
LayoutInflaterinflater= ((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"?><RelativeLayoutxmlns: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 --><TextViewandroid: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 --><TextViewandroid: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"/>
--><TextViewandroid: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
ListViewvideoList= (ListView) findviewByid(_);
CustomChannelListAdapterchannelAdapter=newCustomChannelListAdapter(PlasmaView.this);
videoList.setAdapter(channelAdapter);
Post a Comment for "Populating A Listview With Objects From Parse.com Android"