FloatingActionButton 不会更改 LIstView 中的 EditText 项目

问题描述 投票:0回答:1

我试图通过单击 FloatingActionButton 来更改 ListView 中的 EditText。我想从我的活动中的字符串数组中为每个 ListView 项目编辑Text.setText

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;
    }


}
java android-listview android-edittext floating-action-button getview
1个回答
0
投票

解决方案是创建一个新的字符串数组,重新定义旧的字符串数组并在适配器中接受它。

© www.soinside.com 2019 - 2024. All rights reserved.