Android: Problem with OnItemClickListener
I am a beginner Android developer. I am trying to create an SMS application.
I have created a TabHost
with three TabSpect(ListView,ListView,TextView)
which prints me INBOX
, Send
and in TextView
it prints some useful information.
Now if I am trying to click on any item in ListView
, it will open the SMS manager, where it will be filled with the phoneNumber
of the SMS I clicked.
Every time I try this I receive an error.
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(uriS开发者_如何学编程MSURIs, 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
is returning the position of the selected item but if I use pos
in
Cursor c = getContentResolver().query(uriSMSURIs, null, pos, null, null);
it throws this error:
04-02 07:53:15.504: ERROR/SMSManager(328): value: android.content.ContentResolver$CursorWrapperInner@43e2b800.
I dont know if I can do that this way.
I think the parameters you're passing to the query are the wrong types. Try this:
long id = arg.getItemIdAtPosition(position);
Cursor c = getContentResolver().query(uriSMSURIs, null, "_id = ?", new String[]{Long.toString(id)}, null);
See the documentation for ContentResolver.query.
精彩评论