gpt4 book ai didi

android - OnItemClickListener

转载 作者:IT老高 更新时间:2023-10-28 23:21:39 28 4
gpt4 key购买 nike

当我在以下位置输入此代码时,出现“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/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com