2017-02-04 116 views
1

我試圖讓我的一個項目點擊程序響應,這我的代碼的Android的ListView onItemClickListener錯誤

list.getOnItemClickListener(new AdapterView.OnItemClickListener() { 
     @Override 
     public void onItemClick(AdapterView<?> parent, View view, int position, long id) { 
      Toast.makeText(NumbersActivity.this, "", Toast.LENGTH_SHORT).show(); 
     } 
    }); 

,但我得到這個錯誤

Error:(43, 13) error: method getOnItemClickListener in class AdapterView cannot be applied to given types; required: no arguments found: reason: actual and formal argument lists differ in length where T is a type-variable: T extends Adapter declared in class AdapterView

+2

你需要設置它,而不是得到。 –

回答

0

你必須使用setOnItemClickListener事件。

list.setOnItemClickListener(new AdapterView.OnItemClickListener() { 
    //code 
} 
0

,你必須使用:

ListView list = getListView(); 
    list.setOnItemClickListener(new OnItemClickListener() 
    { 
     @Override 
     public void onItemClick(AdapterView<?> adapter, View v, int position, 
      long arg3) 
     { 
      String value = (String)adapter.getItemAtPosition(position); 
      // assuming string and if you want to get the value on click of list item 
      // do what you intend to do on click of listview row 
     } 
    }); 

也進口:

import android.widget.AdapterView.OnItemClickListener; 
+0

@Mohamed Hisham如果答案有效,請點擊答案的勾號將其標記爲已接受 – rafsanahmad007

相關問題