我正在开发一个消息应用程序,并已使对话列表显示正常,但我的listview onitemclicklistner
遇到问题。我想要检索textview
(id = lblID),将其转换为字符串,然后显示对话列表(将该字符串作为id)并将其显示在我的listview
中。OnItemClickListener/SimpleDateFormat
- 我这样做是否正确?
- 已解决
simplecursoradapter
里面的onitemclicklistener
不会让我用“this”作为上下文,应该用什么来代替? - 我想用
SimpleDateFormat
,我该如何做到这一点之间的光标和适配器? 解决现在我得到一个错误,没有人没有如何解决这个问题?:
7月10日至10日:45:54.926 24231-24231 /? E/AndroidRuntime:致命例外:main 10-10 07:45:54.926 24231-24231 /? E/AndroidRuntime:进程:com.example.wq.myapp,PID:24231 10-10 07:45:54.926 24231-24231 /? E/AndroidRuntime:android.database.sqlite.SQLiteException:接近“*”:语法错误(代码1):编译时:SELECT * FROM(SELECT DISTINCT date * 1 AS normalized_date,NULL AS * FROM sms WHERE(thread_id = 37 AND(type!= 3))UNION SELECT DISTINCT date * 1000 AS normalized_date,NULL AS * FROM pdu LEFT JOIN pending_msgs ON pdu._id = pending_msgs.msg_id WHERE(thread_id = 37 AND msg_box!= 3 AND(msg_box!= 3 AND (m_type = 128 OR m_type = 132 OR m_type = 130)))ORDER BY normalized_date DESC)ORDER BY normalized_date递减
这里是我的代码:
@Override
public void onClick(View v) {
if (v == btnSMS) {
// Create Inbox box URI
Uri inboxURI = Uri.parse("content://mms-sms/conversations");
// Get Content Resolver object, which will deal with Content Provider
ContentResolver cr = getContentResolver();
// Fetch Inbox SMS Message from Built-in Content Provider
Cursor a = cr.query(inboxURI, new String[] {"*"}, null, null, "normalized_date desc");
// Attach Cursor with adapter and display in listView
adapter1 = new SimpleCursorAdapter(this, R.layout.row, a,
new String[]{ "body", "date", "address","_id"},
new int[]{ R.id.lblMsg, R.id.lblDate, R.id.lblNumber, R.id.lblID }, 0);
lvMsg.setAdapter(adapter1);
lvMsg.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
TextView TVConvID = (TextView)findViewById(R.id.lblID);
String ConvID = TVConvID.getText().toString();
Uri ConvURI = Uri.parse("content://mms-sms/conversations/"+ConvID);
Cursor b = getContentResolver().query(ConvURI, new String[]{"*"}, null, null, "normalized_date desc");
adapter2 = new SimpleCursorAdapter(getApplicationContext(), R.layout.convrow, b,
new String[]{ "body", "date", "address" },
new int[]{ R.id.msglblMsg, R.id.msglblDate, R.id.msglblNumber }, 0);
lvMsg.setAdapter(adapter2);
}
});
}
任何帮助或额外的知识会不胜感激。 :)
真棒谢谢堆:)我明白,“这”是返回OnItemClick,我只是不知道如何检索应用程序上下文:) –