Android列表视图数组适配器

时间:2016-03-23 08:38:32

标签: android list view

我正在实施数据列表采用者uisng" simple_list_item_2"内置但我得到错误。它说"来自片段的getview无法应用"它也无法解决" get"得到的符号。(位置)

public class AboutFragment extends Fragment {

        ListView listView2;
        String[] items = {"Friendly Map", "Inc"};

        public AboutFragment() {
            // Required empty public constructor
        }


        @Override
        public View onCreateView(LayoutInflater inflater, ViewGroup container,
                                 Bundle savedInstanceState) {
            // Inflate the layout for this fragment
            View v = inflater.inflate(R.layout.fragment_about, container, false);
            listView2 = (ListView)v.findViewById(R.id.listView2);
            ArrayAdapter arrayAdapter = new ArrayAdapter(getContext(), android.R.layout.simple_list_item_2, items);
            listView2.setAdapter(arrayAdapter);



            return v;
        }

        @Override
        public View getView(int position, View convertView, ViewGroup parent){

            View view = super.getView(position, convertView, parent);
            String[] entry = listView2.get(position);

            return view;

        }


    }

1 个答案:

答案 0 :(得分:0)

试试这个。

public class AboutFragment extends Fragment {

        ListView listView2;
        String[] items = {"Friendly Map", "Inc"};

        public AboutFragment() {
            // Required empty public constructor
        }


        @Override
        public View onCreateView(LayoutInflater inflater, ViewGroup container,
                                 Bundle savedInstanceState) {
            // Inflate the layout for this fragment
            View v = inflater.inflate(R.layout.fragment_about, container, false);
            listView2 = (ListView) v.findViewById(R.id.listView2);
            ArrayAdapter arrayAdapter = new ArrayAdapter(getContext(), android.R.layout.simple_list_item_2, items);
            listView2.setAdapter(arrayAdapter);



            return v;
        }

        @Override
        public View getView(int position, View convertView, ViewGroup parent){

            View view = convertView;
            String entry = listView2.get(position);

            return view;

        }


    }