Recently I have taken a chatting project which uses Android to implement.
In the main page, it shows all the groups. Then if a user click a group, he will be brought into the group page. The chat history will be retrieved. I used a function "printLeftSide" to print all history records. For the first time, it works. But if I click back button and then re-enter the group page, the history records are not seen and disappears. I have traced the "printLeftSide" function and the data is right to add views to the linear layout. The "printLeftSide" function is shown in the following:
void printLeftSide(String s, String name, Date dt)
{
Display display = getWindowManager().getDefaultDisplay();
Point size = new Point();
try {
display.getRealSize(size);
} catch (NoSuchMethodError err) {
display.getSize(size);
}
int width = size.x;
int height = size.y;
LinearLayout llMessageDT = new LinearLayout(this);
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
2*width/5,
LinearLayout.LayoutParams.WRAP_CONTENT);
params.setMargins(10,10,10,10);
llMessageDT.setOrientation(LinearLayout.HORIZONTAL);
llMessageDT.setLayoutParams(params);
DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String dt_ = (String) df.format(dt);
TextView tv3 = new TextView(thisView);
tv3.setTextSize(10);
tv3.setText(dt_);
tv3.setGravity(Gravity.LEFT);
TextView tv = new TextView(thisView);
tv.setTextSize(12);
tv.setText(name+" - ");
tv.setGravity(Gravity.LEFT);
llMessageDT.addView(tv);
llMessageDT.addView(tv3);
TextView tv2 = new TextView(thisView);
tv2.setTextSize(20);
tv2.setText(s);
tv2.setGravity(Gravity.LEFT);
LinearLayout ll = (LinearLayout) findViewById(R.id.messageLinearLayout);
ll.addView(llMessageDT, params);
ll.addView(tv2, params);
}
I am quite confusing about the result. Is there anyone giving some hints to me to solve this problem? Thanks you very much for your attention.