当我在以下代码中输入此代码时,出现错误消息“OnItemClickListener无法解析为类型”:

package com.funkystudios.android.facts;

import android.app.ListActivity;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.ListView;






public class activity2 extends ListActivity {
 @Override
 public void onCreate(Bundle savedInstanceState) {
   super.onCreate(savedInstanceState);

   String[] Facts = getResources().getStringArray(R.array.Facts_Array);
   setListAdapter(new ArrayAdapter<String>(this, R.layout.list, Facts));
   ListView lv = getListView();
   lv.setTextFilterEnabled(true);
   lv.setOnItemClickListener(new OnItemClickListener() {
      public void onItemClick(AdapterView<?> parent, View view,
          int position, long id) {
        // When clicked, show a toast with the TextView text
        Toast.makeText(getApplicationContext(), ((TextView) view).getText(),
            Toast.LENGTH_SHORT).show();
      }
    });

 }
}

它发生在“lv.setOnItemClickListener(new OnItemClickListener(){”。我不确定自己做错了什么。

最佳答案

我想通了,我输入了错误的物品!

import android.app.ListActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.AdapterView.OnItemClickListener;

那是应该的样子。

关于android - OnItemClickListener,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/3929544/

10-11 20:10