android 从列表视图到编辑文本打开消息

发布于 2024-12-26 13:46:16 字数 751 浏览 2 评论 0原文

我正在尝试添加列表视图中收件箱中的消息,这没问题。我想使用该消息将其打开到列表视图下的新编辑文本。

这是我的代码

public List<String> getSMS() {

    // TODO Auto-generated method stub
    List<String> sms = new ArrayList<String>();
    Uri uriSMSURI = Uri.parse("content://sms/inbox");
    Cursor cur = getContentResolver().query(uriSMSURI, null, null, null, null);

    while (cur.moveToNext()) {
         String address = cur.getString(cur.getColumnIndex("address"));
         String body = cur.getString(cur.getColumnIndexOrThrow("body"));
         sms.add("Number: " + address + " .Message: " + body); 

      }
    return sms;
}

,在这段代码中,我想引入字符串“body”并将其打印到新的 Edittext 中。 问题是如何在 getSMS() 方法之外使用“body”变量。 *字符串 body 是消息的正文。

I am trying to add the messages that are in the inbox on the listview and that is ok. I want to use the message to open it to a new edittext that is under of the listview.

here is my code

public List<String> getSMS() {

    // TODO Auto-generated method stub
    List<String> sms = new ArrayList<String>();
    Uri uriSMSURI = Uri.parse("content://sms/inbox");
    Cursor cur = getContentResolver().query(uriSMSURI, null, null, null, null);

    while (cur.moveToNext()) {
         String address = cur.getString(cur.getColumnIndex("address"));
         String body = cur.getString(cur.getColumnIndexOrThrow("body"));
         sms.add("Number: " + address + " .Message: " + body); 

      }
    return sms;
}

From this code I want to bring the String ''body'' and print it to a new Edittext.
The question is how can I use the ''body'' variable outsite of the getSMS() method.
*the String
body is the body of the message.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

灰色世界里的红玫瑰 2025-01-02 13:46:16

您应该创建一个包含两个数据成员的 Message 类:

public class Message {

  private String address;
  private String body;

  public Message( String address, String body ) {
      this.address = address;
      this.body = body;
  }

 public String getAddress() { 
    return address;
 }

 public String getBody() { 
    return body;
 }

}

然后将您的短信存储在 List 而不是 List 中。

然后您将逐条获取您的消息。不要丢失类的信息,它们拥有独立的属性,您应该这样存储它们,不要过早混合它们,让它们独立可用并为此使用对象。

You should create a Message class with two data members :

public class Message {

  private String address;
  private String body;

  public Message( String address, String body ) {
      this.address = address;
      this.body = body;
  }

 public String getAddress() { 
    return address;
 }

 public String getBody() { 
    return body;
 }

}

then store your sms in a List instead of a List.

You will then obtain your messages piece by piece. Don't loose the information of classes, they hold independent properties and you should store them as such, don't mix them to early, let them available indepently and use objects for that.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文