无法解析符号"自定义适配器"



我正在编写我的第一个 android 应用程序,但我无法解决以下问题。

我想制作一个自定义列表,但cannot resolve symbol 'customAdapter'出现错误。

它无法导入或我不知道,因为我不是专家,我只是一个初学者。

变量:

int[] IMAGES = {R.drawable.doctor_1, R.drawable.doctor_1, ...};
String[] NAMES = {"Doctor 1", "Doctor 2", "Doctor 3", ...};
String[] DESCRIPTION = {"MBBS", "MBBS", "MBBS", ...};
String[] TIME = {"4:00pm-10:00pm", "4:00pm-10:00pm", "4:00pm-10:00pm", ...};
String[] FEES = {"RS 2000", "RS 500", ...};

这是代码:

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    android.app.ActionBar actionBar = getActionBar();
    actionBar.setDisplayHomeAsUpEnabled(true);

    ListView listView = (ListView) findViewById(R.id.listview);
    CustomAdapter customAdapter= new CustomAdapter();
    listView.setAdapter(CustomAdapter);
    class CustomAdapter extends BaseAdapter{
        @Override
        public int getCount() {
            return IMAGES.length;
        }
        @Override
        public Object getItem(int i) {
            return null;
        }
        @Override
        public long getItemId(int i) {
            return 0;
        }
        @Override
        public View getView(int i, View view, ViewGroup viewGroup) {
            view = getLayoutInflater().inflate(R.layout.customlayout,null);
            ImageView imageview = (ImageView)view.findViewById(R.id.imageView);
            TextView textView_name=(TextView)view.findViewById(R.id.name);
            TextView textView_description= (TextView)view.findViewById(R.id.description);
            TextView textView_time= (TextView)view.findViewById(R.id.time);
            TextView textView_fees= (TextView)view.findViewById(R.id.fees);
            imageview.setImageResource(IMAGES[i]);
            textView_name.setText(NAMES[i]);
            textView_description.setText(DESCRIPTION[i]);
            textView_time.setText(TIME[i]);
            textView_fees.setText(FEES[i]);
            return view;
        }
    }

使 CustomAdapter 类超出 onSavedInstanceState() 方法的范围:像这样更改:

int[] IMAGES = {R.drawable.doctor_1, R.drawable.doctor_1, R.drawable.doctor_1, R.drawable.doctor_1, R.drawable.doctor_1, R.drawable.doctor_1, R.drawable.doctor_1,
        R.drawable.doctor_1, R.drawable.doctor_1, R.drawable.doctor_1};
String[] NAMES = {"Doctor 1", "Doctor 2", "Doctor 3", "Doctor 4", "Doctor 5", "Doctor 6", "Doctor 7", "Doctor 8", "Doctor 9",
        "Doctor 10"};

String[] DESCRIPTION = {"MBBS", "MBBS", "MBBS", "MBBS", "MBBS",
        "MBBS", "MBBS", "MBBS", "MBBS", "MBBS"};
String[] TIME = {"4:00pm-10:00pm", "4:00pm-10:00pm", "4:00pm-10:00pm", "4:00pm-10:00pm", "4:00pm-10:00pm", "4:00pm-10:00pm", "4:00pm-10:00pm", "4:00pm-10:00pm",
        "4:00pm-10:00pm", "4:00pm-10:00pm"};
String[] FEES = {"RS 2000", "RS 500", "RS 200", "RS 2000", "RS 500", "RS 200", "RS 2000", "RS 500", "RS 200", "RS 1000"};

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    android.app.ActionBar actionBar = getActionBar();
    actionBar.setDisplayHomeAsUpEnabled(true);

    ListView listView = (ListView) findViewById(R.id.listview);
    CustomAdapter customAdapter= new CustomAdapter();
    listView.setAdapter(CustomAdapter);

    }
 class CustomAdapter extends BaseAdapter{
        @Override
        public int getCount() {
            return IMAGES.length;
        }
        @Override
        public Object getItem(int i) {
            return null;
        }
        @Override
        public long getItemId(int i) {
            return 0;
        }
        @Override
        public View getView(int i, View view, ViewGroup viewGroup) {
            view = getLayoutInflater().inflate(R.layout.customlayout,null);
            ImageView imageview = (ImageView)view.findViewById(R.id.imageView);
            TextView textView_name=(TextView)view.findViewById(R.id.name);
            TextView textView_description= (TextView)view.findViewById(R.id.description);
            TextView textView_time= (TextView)view.findViewById(R.id.time);
            TextView textView_fees= (TextView)view.findViewById(R.id.fees);
            imageview.setImageResource(IMAGES[i]);
            textView_name.setText(NAMES[i]);
            textView_description.setText(DESCRIPTION[i]);
            textView_time.setText(TIME[i]);
            textView_fees.setText(FEES[i]);
            return view;
        }

最新更新