how to create method in activity to put it in custom adapter listview?

67 Views Asked by At

at first I got an error " The code of method getView(int, View, ViewGroup) is exceeding the 65535 bytes limit " because I typed too much code, finally I created a method, but the method is error because the variable inside is not detected

I created Method _Differ();

public void _Differ() {
        if (_position == 5) {
            full.setText("iiii");
        }
    }
    

i put method Differ(); in custom adapter listview this is my code in listview custom adapter

public class Listview1Adapter extends BaseAdapter {
        
        ArrayList<HashMap<String, Object>> _data;
        
        public Listview1Adapter(ArrayList<HashMap<String, Object>> _arr) {
            _data = _arr;
        }
        
        @Override
        public int getCount() {
            return _data.size();
        }
        
        @Override
        public HashMap<String, Object> getItem(int _index) {
            return _data.get(_index);
        }
        
        @Override
        public long getItemId(int _index) {
            return _index;
        }
        
        @Override
        public View getView(final int _position, View _v, ViewGroup _container) {
            LayoutInflater _inflater = getLayoutInflater();
            View _view = _v;
            if (_view == null) {
                _view = _inflater.inflate(R.layout.ccc, null);
            }
            
            final LinearLayout linear1 = _view.findViewById(R.id.linear1);
            final LinearLayout linear2 = _view.findViewById(R.id.linear2);
            final LinearLayout linear3 = _view.findViewById(R.id.linear3);
            final LinearLayout linear4 = _view.findViewById(R.id.linear4);
            final TextView textview1 = _view.findViewById(R.id.textview1);
            final TextView full = _view.findViewById(R.id.full);
            final TextView textview2 = _view.findViewById(R.id.textview2);
            final TextView shortt = _view.findViewById(R.id.shortt);
            final TextView name = _view.findViewById(R.id.name);
            final TextView email = _view.findViewById(R.id.email);
            
            full.setText(mapList.get((int)_position).get("end").toString());
            shortt.setText(mapList.get((int)_position).get("rule").toString());
            email.setText(mapList.get((int)_position).get("start").toString());
            _Differ();
            
            return _view;
        }
    }
1

There are 1 best solutions below

2
DARK ENGINE On

//This is your method which will go in your activity >>

public void _Differ(TextView txt, int _position) {
    if (_position == 5) {
        txt.setText("iiii");
    }
}

// This Code Goes in your ListAdpater >>

        full.setText(mapList.get((int)_position).get("end").toString());
        shortt.setText(mapList.get((int)_position).get("rule").toString());
        email.setText(mapList.get((int)_position).get("start").toString());
        _Differ(full, _position);

I think this can help you, By the way, Are you using Sketchware Pro