0
How do I insert the Sqlite data into this listview of my code:
@Override
public void onActivityCreated(Bundle savedInstanceState) {
String[] sCheeseStrings = {"Emerson","Simone","Samara"};
super.onActivityCreated(savedInstanceState);
setListAdapter(new ArrayAdapter<String>(getActivity(),
android.R.layout.simple_list_item_1,sCheeseStrings));
}
the data I want to display is 'TITLE' and 'AUTHOR'.
I’m trying to do that:
public class TabActivity extends Fragment {
private final DataBaseHandler db = new DataBaseHandler(getActivity());
public class TabActivity extends Fragment {
private final DataBaseHandler db = new DataBaseHandler(getActivity());
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
db.addBook(new Book("Android Application Development Cookbook", "Wei Meng Lee"));
db.addBook(new Book("Android Programming: The Big Nerd Ranch Guide", "Bill Phillips and Brian Hardy"));
db.addBook(new Book("Learn Android App Development", "Wallace Jackson"));
View rootView = inflater.inflate(R.layout.activity_tab, container, false);
return rootView;
List<Book> cursor = db.getAllBooks();
String title;
String author;
String[] from = { title, author };
int[] to = { android.R.id.text1, android.R.id.text1 };
SimpleCursorAdapter adapter = SimpleCursorAdapter( getActivity().getApplicationContext(), android.R.layout.simple_list_item_2, cursor, from, to);
}
}
But it is giving an error "The method Simplecursoradapter(Context, int, List, String[], int[]) is Undefined for the type Tabactivity" . What can it be?
Amigo @Emerson Barcellos, you are giving a Return command in the method
onCreateView()
before executing the instructions that create yourSimpleCursorAdapter
. Put the Return statement to the end of the method and the cursor creation before the instructionreturn rootView
. If my answer has helped, mark it as accepted.– Lucas Santos
Another thing. Look at the questions you asked in your profile and see if you have any pending. Any questions you asked and forgot to answer if you were able to find the answer yourself or if someone answered. Try to avoid asking questions and letting them drop without your return. This keeps the Stack Overflow site good.
– Lucas Santos
Wow @Lucassantos I’m almost giving up using Fragment, in Tabhost and Activity I have a working app, and I want to change, but I don’t know how to use the damn Fragment. Well come on...I’ll put the error print, why does it give error?
– Emerson Barcellos
why are you using Tabactivity? This class is obsolete.
– Lucas Santos
OK @Lucassantos thank you so much. I will look for alternatives to solve my problem
– Emerson Barcellos