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

  • Xamarin Blueprints
  • Michael Williams
  • 225字
  • 2021-07-08 11:48:19

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?

主站蜘蛛池模板: 若羌县| 虹口区| 册亨县| 尼玛县| 耿马| 沙雅县| 尼木县| 宁国市| 德兴市| 浦城县| 绥芬河市| 邵武市| 霍城县| 江口县| 武鸣县| 迁安市| 互助| 当阳市| 淅川县| 东乡族自治县| 莫力| 兰西县| 乌兰察布市| 桦甸市| 道孚县| 郎溪县| 新田县| 平山县| 金坛市| 界首市| 云林县| 浏阳市| 曲靖市| 临城县| 商都县| 英山县| 布拖县| 闵行区| 阳朔县| 定南县| 景宁|