Search code examples
androidxmlarraysjsonlistadapter

Res/Arrays affecting TextView


I populate a listview from a JSON object. This works fine

    setListAdapter(new ArrayAdapter<String>(this, R.layout.list_items, name){
        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            View v = convertView;
            if (v == null) {
                LayoutInflater vi = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
                v = vi.inflate(R.layout.list_items, null);
            }
            TextView mDistanceTextView = (TextView) v.findViewById(R.id.listitems_distancetxt);
            TextView mNameTextView = (TextView) v.findViewById(R.id.listitems_nametxt);
            TextView mCategoryTextView = (TextView) v.findViewById(R.id.listitems_categorytxt);
            if (mDistanceTextView != null) {
                mDistanceTextView.setText(distance[position]);
            }
            if (mNameTextView != null) {
                mNameTextView.setText(name[position]);                           
            }
            if(mCategoryTextView != null) {
                mCategoryTextView.setText(type[position]);
                setImage(type[position], v);
            }

            return v;
        }

However in a different activity I want to populate a spinner object so I created a new XML file called arrays.xml and it was located in the res/values folder. When I do this and run the program (without changing any code) the textViews all show null and so don't enter the if statement and so don't populate the view.


Solution

  • In case anybody has stumbled upon this question. It was just a matter of running a clean build