private ArrayList<String> conversation = new ArrayList<String>();
public ArrayAdapter<String> adapter;
private String phoneNumber;
ListView listView;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.converse_view);
this.adapter = new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1, android.R.id.text1,
conversation);
ListView listView = (ListView) findViewById(R.id.conversation);
listView.setAdapter(adapter);
}
protected void onResume()
{
super.onResume();
setContentView(R.layout.converse_view);
this.adapter.notifyDataSetChanged();
}
public void changeNumber(String phoneNumber2) {
this.phoneNumber = phoneNumber2;
}
public void addText(String message) {
conversation.add(message);
}
@Override
public String toString() {
return phoneNumber;
}
public boolean equals(converseView other) {
return this.phoneNumber.equals(other.phoneNumber);
}
I am creating a text messaging app this is my class for the conversation view screen.
addText() is called when you click the send button. How do i get the list view to update so i can see what text messages where send
You need to add the message to the adapter, and notify the adapter that the list has changed.
Basically, the last time that the adapter knows the state of conversation is at:
This will add everything from the ArrayList to the ArrayAdapter, but it doesn’t link them together in any way.