0

我有一个ListView. 当我单击其中一个项目时,它会显示另一个ListView. 例如,现在我希望对第二个Listview进行排序RPname。我怎样才能做到这一点?

这是我的活动

using Android.App;
using Android.Content;
using Android.OS;
using Android.Widget;
using Itsak.Classes;
using AndroidApplication17;

namespace Itsak
{
[Activity(Label = "Record Points", NoHistory = false)]
public class ActivityRecordPoints : Activity
{
    private RecordPointListAdapter _listAdapter;

    protected override void OnCreate(Bundle bundle)
    {
        base.OnCreate(bundle);

        // Create your application here
        SetContentView(Resource.Layout.RecordPointListView);

        //Create adapter
        _listAdapter = new RecordPointListAdapter(this);

        //Find the listview reference
        var listView = FindViewById<ListView>(Resource.Id.lstViewRecordPoints);

        //Hook up adapter to ListView
        listView.Adapter = _listAdapter;
        //Wire up the click event
        listView.ItemClick += ListViewItemClick;
    }

    private void ListViewItemClick(object sender, AdapterView.ItemClickEventArgs e)
    {
        //Get item from the list adapter
        var item = _listAdapter.GetItemAtPosition(e.Position);
        //Make a toast with the item name just to show it was clicked
        Toast.MakeText(this, item.StationName, ToastLength.Short).Show();

        // Invoke ActivityComponents
        var components = new Intent(this, typeof(ActivityComponents));

        StartActivity(components);
    }
}
}

这是我的 XML 文件

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/RecordPointLinearLayout"
android:layout_width="fill_parent"
android:layout_height="80px">
<ImageView
android:id="@+id/imageItemRP"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical" />
<LinearLayout
android:id="@+id/linearTextRP"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:orientation="vertical"
android:layout_marginLeft="10px"
android:layout_marginTop="10px">
    <TextView
    android:id="@+id/textTopRPName"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="TextView" />
    <TextView
    android:id="@+id/textBottomRPCode"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="TextView" />
</LinearLayout>

4

2 回答 2

0

您可以在适配器初始化中对查询进行排序。使用以下命令对数据库查询进行排序:

Cursor c = db.query(DATABASE_TABLE, cols,null, null, null, null,RPName);
于 2013-01-14T09:46:33.223 回答
0

我认为一般的方法是在您的适配器中创建一个排序方法,对包含的数据进行排序。在 Android 上ArrayAdapter确实有一个本机Sort方法,您将比较器作为参数传递给它。

所以我个人会创建一个类似的排序方法,它需要在你的.Comparison DelegateListAdapter

如果您从数据库中获取数据,请使用数据库中内置的排序方法。

于 2013-01-14T09:48:44.350 回答