我正在开发 SMS 应用程序。我能够发送和接收短信。
我有一个名为“收件箱”的标签。单击它时,我会使用 URI content://mms-sms/conversations/
显示所有对话。
当点击任何对话时,我想显示那个人和我之间的所有 SMS 对话。
我已经从 URI content://sms/inbox
中获取了那个人的所有消息,
以及我从 URI content://sms/sent
发给那个人的消息。
现在,我如何在自定义 ListView 中显示这些消息,以便我的消息具有前缀“我”,而其他人的消息具有前缀“<名称/号码>”并根据日期和时间排列?
最佳答案
我正在尝试做类似的事情。你解决了吗?我想我应该手动做! 我认为使用电话号码作为登录名(并非所有公司都将号码存储在手机上),然后将消息号码与记录的号码进行比较。 在布局上你可以有这样的东西:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:weightSum="1.0" >
<TextView
android:id="@+id/txtMessageDate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_marginBottom="5dip"
android:layout_marginLeft="10dip"
android:layout_marginRight="10dip"
android:layout_marginTop="10dip"
android:maxWidth="250dip"/>
<TextView
android:id="@+id/txtMessageRight"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@+id/righttext"
android:layout_marginLeft="16dp"
android:maxWidth="250dip" />
<TextView
android:id="@+id/txtMessageLeft"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_marginLeft="37dp"
android:layout_toRightOf="@+id/lefttext"
android:maxWidth="250dip"/>
</RelativeLayout>
您可以通过您的号码或另一方号码知道登录号码,因此在代码中您可以扩充布局并使用“如果”您可以写下您的姓名或联系人姓名。 类似这样的东西:
if(o.getOriginatingAddress().equals(MainActivity.loggedNumber))
tvOutMessage.setText("me: " + o.getMessageBody());
else
tvInMessage.setText("contact:" + o.getMessageBody());
我不知道这是否是最好的解决方案,但希望它能有所帮助。
关于android - 短信对话,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11949553/