mercredi 29 juillet 2015

Why is my SQLite still not working in my fragments

Hi I am a total newb and programming and I don't know why my codes cant work in the fragment, I followed thenewboston video and made some changes however it still don't work. I added a rootview but other than that I think I did nothing else, someone mind helping a poor soul out?

package com.example.onTV;

import android.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.EditText;
import android.widget.TextView;


public class HistoryFragment extends Fragment {
EditText name;
TextView sqlDisplay;
MyDBHandler dbHandler;

public HistoryFragment() {


}

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

    View rootView = inflater.inflate(R.layout.fragment_history, container, false);
    name = (EditText) rootView.findViewById(R.id.name);
    sqlDisplay = (TextView) rootView.findViewById(R.id.sqlDisplay);
    dbHandler = new MyDBHandler(this.getActivity(), null, null, 1);
    printDatabase();
    return rootView;


}

//Add a product to the database

public void saveOnClicked(View view) {
    favourites favourites = new favourites(name.getText().toString());
    dbHandler.addFavourites(favourites);
    printDatabase();
}

//Delete items
public void deleteOnClicked(View view) {
    String inputText = name.getText().toString();
    dbHandler.deleteFavourites(inputText);
    printDatabase();
}

//Print the database
public void printDatabase() {
    String dbString = dbHandler.databaseToString();
    sqlDisplay.setText(dbString);
    name.setText("");
}

}

Aucun commentaire:

Enregistrer un commentaire