【发布时间】:2026-01-03 22:45:02
【问题描述】:
我在ListView 中有一个Button。
单击时我想转到另一个Activity。
但我收到此错误:No enclosing instance of the type Appointment is accessible in scope
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
View vi=convertView;
if(convertView==null)
vi = inflater.inflate(R.layout.item_row, null);
TextView txtsection = (TextView)vi.findViewById(R.id.section);
TextView txtdoctor = (TextView)vi.findViewById(R.id.doctor);
TextView txtdate = (TextView)vi.findViewById(R.id.date);
TextView txttime = (TextView)vi.findViewById(R.id.time);
btchange = (Button)vi.findViewById(R.id.change);
btchange.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent i = new Intent(context, Available.class);
startActivity(i);
}
});
btdelete = (Button)vi.findViewById(R.id.delete);
txtsection.setText(item.section);
txtdoctor.setText(item.doctor);
txtdate.setText(item.date);
txttime.setText(item.time);
return vi; }}
【问题讨论】:
-
你的适配器是activity的内部类吗?
-
显示完整的适配器。可能你没有提供正确的上下文。
-
您正在创建点击意图,但您从未启动过活动。
-
不要编辑我的答案!发布 cmets 或编辑您的问题。
-
对不起,以后不会再发生了
标签: java android android-listview android-button