官术网_书友最值得收藏!

Creating an XML interface and ListView

Our starting point is the main.xml sheet; this is where we will be creating the ListView:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent"> 
    <ListView 
        android:id="@+id/listView" 
        android:layout_width="fill_parent" 
        android:layout_height="fill_parent" 
        android:layout_marginBottom="10dp" 
        android:layout_marginTop="5dp" 
        android:background="@android:color/transparent" 
        android:cacheColorHint="@android:color/transparent" 
        android:divider="#CCCCCC" 
        android:dividerHeight="1dp" 
        android:paddingLeft="2dp" /> 
</LinearLayout> 

Tip

The main.xml file should already be in the resource | layout directory, so simply copy and paste the previous code into this file.

Excellent! We now have our starting activity and interface, so now we have to create a ListAdapter for our ListView. An adapter works very much like a UITableSource, where we must override functions to determine cell data, row design, and the number of items in the list.

Note

Xamarin Studio also has an Android GUI designer.

Right-click on the Android project and add a new empty class file for our adapter class. Our class must inherit the BaseAdapter class, and we are going to override the following functions:

public override long GetItemId(int position); 
 
public override View GetView(int position, View convertView, ViewGroup parent); 

Before we go any further, we need to create a model for the objects used to contain the data to be presented in each row. In our iOS project, we created a GalleryItem to hold the byte array of image data used to create each UIImage. We have two approaches here: we could create another object to do the same as the GalleryItem, or even better, why don't we reuse this object using a shared project?

主站蜘蛛池模板: 栖霞市| 荆门市| 镇江市| 新竹县| 庄河市| 铜山县| 海安县| 怀化市| 河南省| 建水县| 许昌市| 白城市| 芒康县| 囊谦县| 永吉县| 宣化县| 横山县| 哈巴河县| 杨浦区| 祁连县| 垣曲县| 洛宁县| 平罗县| 甘谷县| 镇宁| 汉川市| 汝州市| 永仁县| 千阳县| 苗栗市| 托克逊县| 金湖县| 海盐县| 郓城县| 射阳县| 介休市| 鲜城| 大同市| 南汇区| 阜城县| 青海省|