0
我是一名初學Android開發人員。我正在嘗試創建一個SMS應用程序。Android:OnItemClickListener問題
我已經創建了三個TabSpect(ListView,ListView,TextView)
它打印我,Send
一個TabHost
和TextView
它打印一些有用的信息。
現在,如果我試圖點擊ListView
中的任何項目,它將打開SMS管理器,它將填充我點擊的SMS的phoneNumber
。
每當我嘗試這個,我收到一個錯誤。
list1.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> arg, View view, int position,long id) {
Uri uriSMSURIs = Uri.parse("content://sms/inbox");
String pos = String.valueOf(position);
Log.d(TAG, "value: " + pos);
Cursor c = getContentResolver().query(uriSMSURIs, null, pos, null, null);
Log.e(TAG, "value: " + c);
String phoneNumber = c.getString(c.getColumnIndex("address"));
Log.e(TAG, "Value: " + phoneNumber;
Intent sendIntent = new Intent(Intent.ACTION_VIEW);
sendIntent.putExtra("address", phoneNumber);
sendIntent.setType("vnd.android-dir/mms-sms");
startActivity(sendIntent);
}
});
pos
正在恢復所選項目的位置,但如果我在
Cursor c = getContentResolver().query(uriSMSURIs, null, pos, null, null);
使用pos
它拋出這個錯誤:
04-02 07:53:15.504: ERROR/SMSManager(328): value: [email protected]
我不知道如果我能做到這辦法。
這與我的變量pos返回相同的值。 (String pos = String.valueOf(position);)所以它沒有工作,我已經閱讀了ContentResolver的文檔。您有沒有其他想法? – Husky 2011-04-02 17:46:54
您嘗試將第三個參數設置爲「_id =?」它仍然沒有工作?在你最初的例子中,你將'pos'傳遞給query()的'selection'參數,而不是'selectionArgs'參數。 – 2011-04-02 18:45:14
是的,但我添加了Log.d(標籤,「Value of:」+ id),它返回相同的值作爲pos – Husky 2011-04-02 19:22:57