dimanche 27 mars 2016

SQLite on a fragment

i'm trying to make a simple SQLite on my android project for some work. Im currently erroring on findViewByID with cannot resolve method , addLyrics cannot resolve method and the (this,null, null,null 1) line with MyDBHandler() in MyDBHandler cannot be applied to this. I have a feeling this to due to this being a fragment instead of the usual activity. Any ideas?

package com.test.test.sql;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;


/**
 * A simple {@link Fragment} subclass.
 */
public class MemoFragment extends Fragment {

    EditText Input;
    TextView LyricText;
    MyDBHandler dbHandler;
    Button addButtonClicked;
    Button deleteButtonClicked;

    public MemoFragment() {
        // Required empty public constructor
    }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        return inflater.inflate(R.layout.fragment_memo, container, false);

        Input = (EditText) findViewById (R.id.Input);
        LyricText = (TextView) findViewById (R.id.LyricText);
        dbHandler = new MyDBHandler(this, null, null, 1);
        printDatabase ();
    }
    //add lyric to database
    public void addButtonClicked(View view){
        Lyrics lyrics = new Lyrics(Input.getText().toString());
        dbHandler.addLyrics(lyrics);
        printDatabase();
    }

    //delete items
    public void deleteButtonClicked(View view){
        String inputText = Input.getText().toString());
        dbHandler.deleteLyrics(inputText);
        printDatabase();
    }

    public void printDatabase(){
        String dbString = dbHandler.databasetoString();
        LyricText.setText(dbString);
        Input.setText("");
    }

}

Aucun commentaire:

Enregistrer un commentaire