2013-08-20 36 views
0

我有一個customlistadapter和的onclick聽者一個listactivity不被當我從列表ListAdapter OnClickListener不會被調用

下面觸碰某個項目堪稱是我的onCreate方法

protected override void OnCreate(Bundle bundle) 
    { 
     base.OnCreate(bundle); 
     SetContentView(Resource.Layout.listitem); 
       List<AvailableFeatures> listIntfeats = VehicleAssetsDB.GetAvailableFeatures(2); 
       CustomAdapter ca = new CustomAdapter(this, listIntfeats); 
       ListAdapter = ca; 
    } 

下面是我的onlistitemclick聽衆

protected override void OnListItemClick(ListView l, View v, int position, long id) 
    { 
    System.Console.Writeline("test"); 
    } 

但是當我從列表中選擇一個項目什麼都不會發生。

感謝

+0

變化'的System.Console.WriteLine( 「測試」);''到Log.d( 「標籤」, 「測試」);'然後查看logcat的 – petey

+0

這沒有解決問題 –

+0

你在哪裏分配你的點擊監聽器? – dymmeh

回答

0

我不知道你是什麼設置爲您的內容來看,好像你正試圖爲每個列表項有看法,而是應該由你的適配器GetView處理。這裏一個簡單的測試工作得很好:

public class Activity1 : ListActivity 
{ 
    protected override void OnCreate(Bundle bundle) 
    { 
     base.OnCreate(bundle); 

     var stupidStuff = new[] {"One", "Two", "Three"}; 
     ListAdapter = new ArrayAdapter(this, Android.Resource.Layout.SimpleListItem1, stupidStuff); 
    } 

    protected override void OnListItemClick(ListView l, View v, int position, long id) 
    { 
     System.Diagnostics.Debug.WriteLine("Item {0} clicked", position + 1); 
    } 
}