1

I want to make a ListView from the time that I get from a TimePicker' I succeed to add the time into a variable. but when I'm trying to add them into the ListView I don't get anything.

    addArray = new ArrayList<String>();
    ArrayAdapter<String> adapter = new ArrayAdapter(chart_houres_cosher.this,android.R.layout.simple_list_item_1,addArray);
    ListView listView = (ListView) findViewById(R.id.leassons);
    listView.setAdapter(adapter);

Clicked button

    textView.setText( firstHouer + " : " + firstdMinute + " - " + seccoundHouer + " : " + seccoundMinute );
    addArray.add(firstHouer + " : " + firstdMinute + " - " + seccoundHouer + " : " + seccoundMinute);

I can see the outcome on the TextView but not on the ListView.

2 Answers 2

3

Once you change the data of adapter you have to invoke notifyDataSetChanged() to see the effects in the list view.

textView.setText( firstHouer + " : " + firstdMinute + " - " + seccoundHouer + " : " + seccoundMinute );
addArray.add(firstHouer + " : " + firstdMinute + " - " + seccoundHouer + " : " + seccoundMinute);
addArray.notifyDataSetChanged();
//^^^^^^^^^^^^^^^^^^^
// once adapter is linked and later data source is modified , notify it
// only then adapter go though the data source 
//and update the listView/RecyclerView accordingly
Sign up to request clarification or add additional context in comments.

1 Comment

@Mayli Plus why use same string concatenation again in the addArray.add() when you can use addArray.add(textView.getText()) or as string concatenation is not even recommended to be used with setText(), set it to a temp string and pass it to both setText() and add().
1

And where is your data? From your code you are trying to add an empty Array.

addArray = new ArrayList<String>();

You just declare addArray, it dosen't have any data in it. And you are adding empty array into ListView.

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.