【发布时间】:2014-12-25 17:23:42
【问题描述】:
我正在为 ListView 使用自定义适配器 (BaseAdapter) 来显示我的程序中的对象列表。我已经根据我在网上找到的教程 (http://www.codelearn.org/android-tutorial/android-listview) 实现了所有内容,但是在我的 Adapter 类的 getView() 方法中尝试设置 LayoutInflater 时出现错误。
public View getView(int arg0, View arg1, ViewGroup arg2) {
if(arg1==null) {
LayoutInflater inflater =(LayoutInflater)EventListActivity.this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
arg1 = inflater.inflate(R.layout.eventitem, arg2, false);
}
EventListActivity 是我所在的“MainActivity”:
public class EventListActivity extends Activity {
private ListView listview;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.event_list);
//setting adapter to event list view
EventBaseAdapter eventadapter = new EventBaseAdapter();
listview = (ListView)findViewById(R.id.eventlist);
listview.setAdapter(eventadapter);
}
我在创建 LayoutInflater 的 Adapter 类中的“EventListActivity.this”部分出现错误,提示“在范围内无法访问 EventListActivity 类型的封闭实例”。我不知道这意味着什么,我很乐意听取你们的任何建议或帮助。
提前致谢!
【问题讨论】:
-
您的适配器类与 EventListActivity 属于同一类?
-
不,它们在两个不同的文件中。
标签: android listview android-listview baseadapter