我正在尝试开发一个短信应用程序。我已经成功地从列表视图中的收件箱中检索了所有短信,但现在我被困在一个点上。我想要这样,当用户单击任何线程时,它应该在详细视图中打开该线程。我怎样才能做到这一点?我正在粘贴关于我到底想要什么的图片以及我为检索短信列表而编写的代码。
public class Inbox extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_inbox);
ListView list = (ListView) findViewById(R.id.list);
List<String> msgList = getSMS();
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1, msgList);
list.setAdapter(adapter);
}
public List<String> getSMS() {
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;
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.activity_inbox, menu);
return true;
}
}