从列表视图检索消息并打印到编辑文本
我怎样才能做到这一点。我尝试了很多方法。 但我不能。 我所做的唯一工作就是用消息填充列表。但当我触摸它时,它没有任何作用。我怎样才能使列表可点击并获取消息?
这是我的代码和列表。它会读取收件箱,
ListView lViewSMS = (ListView) findViewById(R.id.listViewSMS);
if(fetchInbox()!=null)
{
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, fetchInbox());
lViewSMS.setAdapter(adapter);
}
}
public ArrayList<String> fetchInbox() {
ArrayList<String> sms = new ArrayList<String>();
Uri uriSms = Uri.parse("content://sms/inbox");
Cursor cursor = getContentResolver().query(uriSms, new String[]{"_id", "address", "date", "body"},null,null,null);
cursor.moveToFirst();
while (cursor.moveToNext())
{
String address = cursor.getString(1);
String body = cursor.getString(3);
System.out.println("======> Mobile number => "+address);
System.out.println("=====> SMS Text => "+body);
sms.add(address+"\n"+body);
}
return sms;
}
请帮助我在我的代码中添加什么内容。
how can i do that. i try many ways.
but i cant .
the only i did and work is to fill the list with messages. but when i touch that it doesnt do anything. how can i make the list clickable and get the messages ?
here is my code with the list . it reads the inbox
ListView lViewSMS = (ListView) findViewById(R.id.listViewSMS);
if(fetchInbox()!=null)
{
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, fetchInbox());
lViewSMS.setAdapter(adapter);
}
}
public ArrayList<String> fetchInbox() {
ArrayList<String> sms = new ArrayList<String>();
Uri uriSms = Uri.parse("content://sms/inbox");
Cursor cursor = getContentResolver().query(uriSms, new String[]{"_id", "address", "date", "body"},null,null,null);
cursor.moveToFirst();
while (cursor.moveToNext())
{
String address = cursor.getString(1);
String body = cursor.getString(3);
System.out.println("======> Mobile number => "+address);
System.out.println("=====> SMS Text => "+body);
sms.add(address+"\n"+body);
}
return sms;
}
please help of what to add on my code.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要为lViewSMS编写OnItemClicklistener。
这是android链接 ListView
You need to write OnItemClicklistener for lViewSMS.
Here is android link ListView