数据绑定错误:找不到符号方法setDbSavedLocationsFragment(DbSavedLocationsFragment)

时间:2018-10-23 06:59:35

标签: android

我认为我对我的代码进行了一些细微的更改后会收到此错误,但我无法弄清楚。可能在xml中。虽然不确定。有人可以帮我找出解决方法。我检查了生成的数据绑定类,没有方法可以为该类设置Fragment。但是在其他类中。工作正常。

DbsavedLocationsFragment.class

 package genesis.com.getlocation.fragments;


import android.app.AlertDialog;
import android.arch.lifecycle.Observer;
import android.content.DialogInterface;
import android.databinding.DataBindingUtil;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Spinner;
import android.widget.Toast;

import com.google.android.gms.common.util.DataUtils;

import java.util.ArrayList;
import java.util.List;

import genesis.com.getlocation.database.DatabaseController;
import genesis.com.getlocation.database.LocationDetails;
import genesis.com.getlocation.databinding.FragmentSavedLocationsBinding;
import genesis.com.getlocation.util.ListAdapter;
import genesis.com.getlocation.R;
import genesis.com.getlocation.util.JsonParsing;
// naming
public class DbSavedLocationsFragment extends Fragment {
    private final String TAG = DbSavedLocationsFragment.class.getSimpleName();
    private String selectedSpinnerType;
    private RecyclerView savedLocationInfoTextView;
    private static DatabaseController databaseController;

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        databaseController = new DatabaseController(getContext());
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {

        FragmentSavedLocationsBinding fragmentSavedLocationsBinding = DataBindingUtil.inflate(inflater,
                R.layout.fragment_saved_locations,
                null,
                false);
        View view = fragmentSavedLocationsBinding.getRoot();
        fragmentSavedLocationsBinding.setDbSavedLocationsFragment(this);
        savedLocationInfoTextView = fragmentSavedLocationsBinding.idRecyclerList;
        savedLocationInfoTextView.setClickable(true);
        final Spinner spinner = fragmentSavedLocationsBinding.spinner;
        ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(getContext(), R.array.type_array, R.layout.support_simple_spinner_dropdown_item);
        adapter.setDropDownViewResource(R.layout.support_simple_spinner_dropdown_item);
        spinner.setAdapter(adapter);
        spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
            public void onItemSelected(AdapterView<?> parent, final View view, int pos, long id) {
                selectedSpinnerType = parent.getItemAtPosition(pos).toString();
                if (selectedSpinnerType.equals(getString(R.string.all))) {
                    loadAllLocations();
                } else
                    loadSelectedLocationType();
            }

            public void onNothingSelected(AdapterView<?> parent) {
                Toast.makeText(getContext(), R.string.user_selected_nothing, Toast.LENGTH_SHORT).show();
            }
        });
        return view;
    }

    private void loadSelectedLocationType() {
        databaseController.loadAllRecordsOfType(selectedSpinnerType).observe(DbSavedLocationsFragment.this, new Observer<List<LocationDetails>>() {
            @Override
            public void onChanged(@Nullable List<LocationDetails> location_obj) {
                Log.e(TAG, location_obj.size() + " saved Locations in " + selectedSpinnerType);
                JsonParsing jsonParsing = new JsonParsing(location_obj);
                ArrayList<Bundle> locationList = jsonParsing.parseData();
                savedLocationInfoTextView.setAdapter(new ListAdapter(locationList, new deleteRecordInterface() {
                    @Override
                    public void deleteRecordCallback(final int recordId, final String name) {
                        new AlertDialog.Builder(getContext())
                                .setTitle(R.string.delete_record)
                                .setMessage(getString(R.string.are_you_sure_you_want_to_delete) + name)
                                .setIcon(android.R.drawable.ic_dialog_alert)
                                .setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
                                    public void onClick(DialogInterface dialog, int whichButton) {
                                        deleteRecord(recordId);
                                    }
                                })
                                .setNegativeButton(android.R.string.no, null).show();
                    }
                }));
                savedLocationInfoTextView.setLayoutManager(new LinearLayoutManager(getActivity()));
            }
        });
    }

    private void loadAllLocations() {
        databaseController.loadAllRecords().observe(DbSavedLocationsFragment.this, new Observer<List<LocationDetails>>() {
            @Override
            public void onChanged(@Nullable List<LocationDetails> location_obj) {
                Log.e(TAG, location_obj.size() + " saved Locations in " + selectedSpinnerType);
                JsonParsing jsonParsing = new JsonParsing(location_obj);
                ArrayList<Bundle> locationList = jsonParsing.parseData();
                savedLocationInfoTextView.setAdapter(new ListAdapter(locationList, new deleteRecordInterface() {
                    @Override
                    public void deleteRecordCallback(final int recordId, final String name) {
                        new AlertDialog.Builder(getContext())
                                .setTitle(R.string.delete_record)
                                .setMessage(getString(R.string.are_you_sure_you_want_to_delete) + name)
                                .setIcon(android.R.drawable.ic_dialog_alert)
                                .setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
                                    public void onClick(DialogInterface dialog, int whichButton) {
                                        deleteRecord(recordId);
                                    }
                                })
                                .setNegativeButton(android.R.string.no, null).show();
                    }
                }));
                savedLocationInfoTextView.setLayoutManager(new LinearLayoutManager(getActivity()));
            }
        });
    }

    private void deleteRecord(int deleteRecordWithId) {
        databaseController.deleteRecord(deleteRecordWithId);
    }

    public interface deleteRecordInterface {
        void deleteRecordCallback(int recordId, String name);
    }

}

FragmentSavedLocationsBinding.class

package genesis.com.getlocation.databinding;

import android.databinding.DataBindingComponent;
import android.databinding.DataBindingUtil;
import android.databinding.ViewDataBinding;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Spinner;

public abstract class FragmentSavedLocationsBinding extends ViewDataBinding {
  @NonNull
  public final RecyclerView idRecyclerList;

  @NonNull
  public final Spinner spinner;

  protected FragmentSavedLocationsBinding(DataBindingComponent _bindingComponent, View _root,
      int _localFieldCount, RecyclerView idRecyclerList, Spinner spinner) {
    super(_bindingComponent, _root, _localFieldCount);
    this.idRecyclerList = idRecyclerList;
    this.spinner = spinner;
  }

  @NonNull
  public static FragmentSavedLocationsBinding inflate(@NonNull LayoutInflater inflater,
      @Nullable ViewGroup root, boolean attachToRoot) {
    return inflate(inflater, root, attachToRoot, DataBindingUtil.getDefaultComponent());
  }

  @NonNull
  public static FragmentSavedLocationsBinding inflate(@NonNull LayoutInflater inflater,
      @Nullable ViewGroup root, boolean attachToRoot, @Nullable DataBindingComponent component) {
    return DataBindingUtil.<FragmentSavedLocationsBinding>inflate(inflater, genesis.com.getlocation.R.layout.fragment_saved_locations, root, attachToRoot, component);
  }

  @NonNull
  public static FragmentSavedLocationsBinding inflate(@NonNull LayoutInflater inflater) {
    return inflate(inflater, DataBindingUtil.getDefaultComponent());
  }

  @NonNull
  public static FragmentSavedLocationsBinding inflate(@NonNull LayoutInflater inflater,
      @Nullable DataBindingComponent component) {
    return DataBindingUtil.<FragmentSavedLocationsBinding>inflate(inflater, genesis.com.getlocation.R.layout.fragment_saved_locations, null, false, component);
  }

  public static FragmentSavedLocationsBinding bind(@NonNull View view) {
    return bind(view, DataBindingUtil.getDefaultComponent());
  }

  public static FragmentSavedLocationsBinding bind(@NonNull View view,
      @Nullable DataBindingComponent component) {
    return (FragmentSavedLocationsBinding)bind(component, view, genesis.com.getlocation.R.layout.fragment_saved_locations);
  }
}

fragment_saved_locations.xml

<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:android="http://schemas.android.com/apk/res/android">

    <data>
        <variable
            name="showDialogFragmentViewModel"
            type="genesis.com.getlocation.viewmodelpackage.ShowDialogFragmentViewModel" />
        <variable
            name="showDialogFragment"
            type="genesis.com.getlocation.fragments.ShowDialogFragment" />
    </data>

    <android.support.constraint.ConstraintLayout
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        tools:context=".MapsActivity"
        tools:layout_editor_absoluteY="81dp">

        <TextView
            android:id="@+id/id_text_field"
            android:layout_width="300dp"
            android:layout_height="211dp"
            android:layout_marginStart="44dp"
            android:layout_marginTop="24dp"
            android:layout_marginEnd="40dp"
            android:text="@{showDialogFragmentViewModel.locationDetails}"
            android:layout_marginBottom="25dp"
            app:layout_constraintBottom_toTopOf="@+id/id_edit_text"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent"
            app:layout_constraintVertical_chainStyle="spread_inside" />

        <TextView
            android:id="@+id/textView"
            android:layout_width="wrap_content"
            android:layout_height="0dp"
            android:layout_marginStart="28dp"
            android:layout_marginTop="264dp"
            android:layout_marginEnd="298dp"
            android:layout_marginBottom="17dp"
            android:text="@string/add_note"
            app:layout_constraintBottom_toTopOf="@+id/id_edit_text"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent" />

        <EditText
            android:id="@+id/id_edit_text"
            android:layout_width="306dp"
            android:layout_height="59dp"
            android:layout_marginStart="16dp"
            android:layout_marginTop="25dp"
            android:ems="10"
            android:inputType="textPersonName"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@+id/id_text_field" />

        <RadioGroup
            android:id="@+id/radioGroup"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginStart="62dp"
            android:layout_marginTop="21dp"
            android:layout_marginEnd="234dp"
            android:layout_marginBottom="19dp"
            app:layout_constraintBottom_toTopOf="@+id/id_no"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@+id/id_edit_text">

            <RadioButton
                android:id="@+id/id_radio_button_1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:checked="false"
                android:clickable="true"
                android:onClick="onRadioButtonClicked"
                android:text="@string/maximus"
                android:focusable="true" />

            <RadioButton
                android:id="@+id/id_radio_button_2"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:clickable="true"
                android:focusable="true"
                android:onClick="onRadioButtonClicked"
                android:text="@string/desimus" />

            <RadioButton
                android:id="@+id/id_radio_button_3"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:clickable="true"
                android:focusable="true"
                android:onClick="onRadioButtonClicked"
                android:text="@string/meridus" />
        </RadioGroup>

        <Button
            android:id="@+id/id_no"
            android:layout_width="wrap_content"
            android:layout_height="44dp"
            android:layout_marginStart="80dp"
            android:layout_marginEnd="44dp"
            android:layout_marginBottom="16dp"
            android:onClick="@{(v) -> showDialogFragment.onDialogButtonClicked(v)}"
            android:text="@string/cancel"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toStartOf="@+id/id_yes"
            app:layout_constraintHorizontal_bias="0.5"
            app:layout_constraintStart_toStartOf="parent" />

        <Button
            android:id="@+id/id_yes"
            android:layout_width="wrap_content"
            android:layout_height="44dp"
            android:layout_marginStart="44dp"
            android:layout_marginTop="132dp"
            android:layout_marginEnd="84dp"
            android:layout_marginBottom="16dp"
            android:onClick="@{(v) -> showDialogFragment.onDialogButtonClicked(v)}"
            android:text="@string/confirm"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toEndOf="@+id/id_no"
            app:layout_constraintTop_toBottomOf="@+id/id_edit_text"
            app:layout_constraintVertical_bias="1.0" />

    </android.support.constraint.ConstraintLayout>

</layout>

0 个答案:

没有答案