代码如下:
Cursor cursor = mydatabasehelper.fetchAllData1(type);
if(cursor != null){     
while (cursor.moveToNext()) { 
String name = cursor.getString(cursor.getColumnIndex("type")); 
Log.v("info", "类型是 " + name ); 


if (cur != null && name.equals("发送")) {                                        //1213
System.out.println("发送(green)++++++++++++");
simpleadapter = new SimpleCursorAdapter(this,R.layout.list_say_he_item,cur, 
new String[] {"type","det","tim" }, new int[] {R.id.neirong,R.id.single_text,R.id.tim2});    
}else{
System.out.println("接收(white)————————");
simpleadapter = new SimpleCursorAdapter(this,R.layout.singletext,cur, 
new String[] {"type","det","tim" }, new int[] {R.id.send_receive_text,R.id.single_text,R.id.tim2});
}
setListAdapter(simpleadapter);
simpleadapter.notifyDataSetChanged();

cursor.close(); 

得到结果老是只显示一种layout,如何在会话中根据name的值,显示不同layout,求大神帮忙android短信会话

解决方案 »

  1.   

    你可以在R.layout中多写几种xml文件啊
      

  2.   

    我定义了两个layout,根据name的值不同,显示不同的layout,但始终只显示一种;如name=发送时,显示第一个的,当又收到一条信息name=接收时,前面所有的显示风格全变成了第二个layout的,求解决方案
      

  3.   

    上面那两个layout是在这个activity本身对应的xml文件的list中显示的,在list中有两种显示方式
    第一个layout,发送时这样显示:
    当收到信息时,显示为
    这时应该调用第二个layout界面,但是为什么发送的那条信息的显示界面也变成第二个的了?
      

  4.   

    你说的这两种风格类似于手机接收和发送短信的那两种风格。我感觉你的错误可能在于那个if  else 语句运用上,我没有试,但是我感觉问题在那里,你用一下那个if(){}  else if(){}语句试试