1

I'm trying to change the EditText in my ListView by clicking the FloatingActionButton. I want to editText.setText from an array of strings from my activity for every ListView item

public class TestAdapter extends ArrayAdapter<String> {
    private Context context;
    private String [] names;
    private String [] data;
    private ActivityWifiBinding binding;
    public TestAdapter(@NonNull Context context, String[] names, String[] data, ActivityWifiBinding binding) {
        super(context, R.layout.test_list_item, names);
        this.names = names;
        this.context = context;
        this.data = data;
        this.binding = binding;
    }

    @NonNull
    @Override
    public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
        LayoutInflater layoutInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

        convertView = layoutInflater.inflate(R.layout.test_list_item, parent,false);

        TextView name = (TextView) convertView.findViewById(R.id.text_test);
        name.setText(this.names[position]);

        EditText editText = (EditText) convertView.findViewById(R.id.editTextText_test);
        ImageButton button = (ImageButton) convertView.findViewById(R.id.button_test);
        button.setOnClickListener(v -> editText.setText((this.data[position])));
        binding.floatingButtonTest.setOnClickListener(v1 -> editText.setText(this.data[position]));
        return convertView;
    }


}

1 Answer 1

0

The solution was to create a new String array, redefine the old String array and accept it in the adapter.

Sign up to request clarification or add additional context in comments.

2 Comments

Could you post your new version ?
I gave up the FloatingButtonSolution becouse of specific my app. You need to create new String array, than in setOnclickListener redefine your Adapter (Adapter xxx = new Adapter (New String Array); adapter.setAdapter(xxx);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.