我有一个自定义arrayadapter类,它有3个textviews:请求标题,日期和最新消息。我在我的主要活动中调用该类,并从位于手机内存中的文本文件中读取。当我从服务器收到消息时,如何将最新消息更改为服务器而不是文本文件?
我的主要活动
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();
}
同一活动的广播接收器
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");
}
};
我是否重写文件中的行并刷新列表?