I have a custom arrayadapter class that has 3 textviews: Request Title, Date and Latest Message. I call that class in my main activity and that reads from a textfile sitting in the phones memory. When I receive a message from my server, how can I change the Latest Message to the one from the server instead of the text file?
My Main Activity
listView = (ListView)findViewById(R.id.lv_requests);
ra = new RequestAdapter(getApplicationContext(),R.layout.request_adapter);
listView.setAdapter(ra);
Date date = new Date();
if(fileExists("requests")==true){
try{
BufferedReader inputReader = new BufferedReader(new InputStreamReader(openFileInput("requests")));
String in = null;
while((in=inputReader.readLine())!=null){
//localbroadcast manager update here
String[] split = in.split(Pattern.quote("|"));
String requestTitle = split[0];
String requestDate = split[2];
String latestMessage = split[3];
String registrationID = split[1];
String audioPath = split[4];
String fileTitle = split[5];
String textPath = "";
Date convDate = convert(requestDate);
Request newRequest = new Request(requestTitle,registrationID,convDate,latestMessage, audioPath,textPath,fileTitle);
userReqs.add(newRequest);
ra.add(newRequest);
}
}catch (IOException e){
e.toString();
}
The broadcast receiver on the same activity
private BroadcastReceiver onNotice = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
String str = intent.getStringExtra("msg");
String requestTitle = intent.getStringExtra("requestTitle");
String latestMessage = intent.getStringExtra("latestMsg");
}
};
Do I rewrite the line in the file and refresh the list?