0

Okay so i have a database, and i want it so you can favorite items.

Would i make it so you can save items then it will load it into a list view?

this is my load thing

//Calls the database, gets a list of names.
    // if listofnames.size()==0 keep name, otherwise
    // change name to first name.
    ArrayList<String> nameList = new ArrayList<String>();
    favList = db.getName();
    if(favList.size()>0){
        name.setText(favList.get(0));

But that just sets a text i want it to add items..

1
  • Put more info and code.. so that people can understand what are the variables you're using and why .. Commented Feb 3, 2012 at 4:36

2 Answers 2

1

You may use ArrayAdapter or SimpleAdapter or BaseAdapter - through which you may bind dataSource (List<T>) to the ListView.

Sign up to request clarification or add additional context in comments.

2 Comments

Or even better - SimpleCursorAdapter.
@MisterSquonk - Yes! but in OP, ArrayList<T> is used so I mentioned.
0

You can do this as follows

public class MyClass extends ListActivity{
    public void onCreate(Bundle bundle){
        //get the names from database
        setListAdapter(new ArrayAdapter<E>(this,R.layout.xml_filename,your_list);
    }
}

Remember in this case your xml file should be the TextView (I.e the items what list view should contain). You cannot pass an xml file with a ListView directly.

If you have still some problem, then post your code which can be solved.

You can follow the given link for more clarification. http://developer.android.com/resources/tutorials/views/hello-listview.html

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.