I've been trying to implement a simple SQLite db into a fragment of my application I am creating. Ive been informed that due to it being a fragment I cannot have my onClicks in my XML as the Java cannot find them, so for a while iv been searching for methods of implementing my buttons directly into the Java instead and maybe even the input and result text if necessary but all information I have found have been specific to Activities and everything else I receive that Cannot Resolve Symbol “OnClickListener”
If anyone has any ideas it would be much appreciated
package com.test.test.app;
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
View v = inflater.inflate(R.layout.fragment_memo, container, false);
Input = (EditText) v.findViewById(R.id.Input);
LyricText = (TextView) v.findViewById (R.id.LyricText);
dbHandler = new MyDBHandler(getActivity() ,null, null, 1);
printDatabase ();
return v;
}
//add lyric to database
public void addButtonClicked(View view){
Lyrics lyrics = new Lyrics(Input.getText().toString());
dbHandler.addLyric(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