繁体   English   中英

无法解析符号“customAdapter”

[英]Cannot resolve symbol 'customAdapter'

我正在编写我的第一个 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;
        }

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM