listview setonitemclicklistener with arrayadapter

时间:2016-01-02 21:53:52

标签: android listview android-adapterview

当试试tu add方法时setOnItemClikListener告诉我这个错误:AdapterView中的setOnItemClikListener(ItemClikListener)无法应用于()。

我的代码是:

List<String> weekForecast = new ArrayList<String>(Arrays.asList(forecastArray));
    mForecastAdapter = new ArrayAdapter<String>(getActivity(),R.layout.list_item_forecast,R.id.list_item_forecast_textview,weekForecast);

    ListView listViewForecast = (ListView) rootView.findViewById(R.id.listview_forecast);
    listViewForecast.setAdapter(mForecastAdapter);
    listViewForecast.setOnItemClickListener();

1 个答案:

答案 0 :(得分:3)

尝试以下方法:

List<String> weekForecast = new ArrayList<String>(Arrays.asList(forecastArray));

    mForecastAdapter = new ArrayAdapter<String>
            (getActivity(),android.R.layout.simple_list_item1,weekForecast);

    ListView listViewForecast = (ListView) rootView.findViewById(R.id.listview_forecast);
    listViewForecast.setAdapter(mForecastAdapter);

    listViewForecast.setOnItemClickListener(new OnItemClickListener() {
              public void onItemClick(AdapterView<?> parent, View view,
                      int position, long id) {
                       //Do your thing here

                  }
                });