K
K
kakatak2016-04-13 21:30:40
Android
kakatak, 2016-04-13 21:30:40

How to correctly handle the click event on an element that lies in the item ListView with subsequent updating of the entire ListView from the ListFragment?

There is a ListFragment in which a complex ListView with buttons is formed with the help of an adapter.
It is necessary to hang a click handler on these buttons (Item ListView elements) so that I can rebuild the entire list based on the changed element in the list row, and display it - the already changed list in the same ListFragment.
In the expanse of the stack, there are many options to bind the click handler in the getView function of the Adapter class. It all works, but it is not clear how to rebuild the list from the adapter, perhaps another solution is needed for this. Maybe you can handle clicks in the fragment class itself, then all questions will disappear.
What is now:

@Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_form_schedule, null);
        String test = "0%4#09%00%18%00%13%00%14%00;5%5#09%00%17%00%13%00%14%00";
        adapter = new ScheduleAdapter(getActivity(), test.split(";"));
        ListView listView = (ListView)view.findViewById(android.R.id.list);
        View footerView = inflater.inflate(R.layout.item_change_schelude, null);
        listView.setAdapter(adapter);
....

public class ScheduleAdapter extends ArrayAdapter<String> {

    String scheduleCodedString;
    public ScheduleAdapter(Context context, String[] periodsScheduleCodedString) {
        super(context, 0, periodsScheduleCodedString);
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        if (convertView == null) {
            convertView = LayoutInflater.from(getContext()).inflate(R.layout.item_change_schelude, parent, false);
        }
        ToggleButton bt = (ToggleButton) convertView.findViewWithTag("weekDay0");
        bt.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
               //во время этого события мне нужно зареплейсить элементы списка на актуальные.
                Log.i("Test", v.getTag().toString());
            }
        });
.....

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Denis Zagaevsky, 2016-04-13
@kakatak

Calculate new list items, put them in the adapter and call notifyDataSetChanged(). And that's it.
By the way, read about the concept of ViewHolders, you need it.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question