Q1: Когда я запускаю приложение, оно работает нормально, без проблем, но данные из базы данных не отображаются, данные вставляются в базу данных, но не отображаются в приложении на ListView во фрагменте.
Q2: Как добавить кнопку в ListView и управлять ею для каждого id
в адаптере курсора?
Спасибо.:)
public class fragment extends Fragment {
View view;
ListView locationListView;
public static boolean isDataUpdated = false;
Cursor cursor;
LocationCursorAdapter locationCursorAdapter;
public fragment() {
}
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
view = inflater.inflate(R.layout.activity_getlost1, container, false);
// Find the ListView which will be populated with the pet data
locationListView = view.findViewById(R.id.list);
FloatingActionButton floatingActionButton = view.findViewById(R.id.fab2);
floatingActionButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent = new Intent(getActivity(), Map.class);
startActivity(intent);
}
});
locationListView = view.findViewById(R.id.list);
populateList();
return view;
}
private void populateList() {
locationCursorAdapter = new LocationCursorAdapter(getActivity(), cursor);
// Find and set empty view on the ListView, so that it only shows when the list has 0 items.
View emptyView = view.findViewById(R.id.layout);
locationListView.setEmptyView(emptyView);
locationListView.setAdapter(locationCursorAdapter);
}
@Override
public void onResume() {
super.onResume();
if (isDataUpdated) {
cursor.requery();
locationCursorAdapter.notifyDataSetChanged();
fragment.isDataUpdated = false;
}
}
}
ListView
<ListView
android:layout_below="@id/line1"
android:id="@+id/list"
class="android.support.v7.app.AlertController$RecycleListView"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_margin="15dp"
android:dividerHeight="10dp" />