Android的:问题OnItemClickListener [英] Android: Problem with OnItemClickListener

查看:157
本文介绍了Android的:问题OnItemClickListener的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是初学者Android开发者。我试图创建一个SMS应用。

I am a beginner Android developer. I am trying to create an SMS application.

我创建了一个 TabHost TabSpect(ListView控件,ListView中,TextView的)它打印我收件箱发送的TextView 它打印一些有用的信息。

I have created a TabHost with three TabSpect(ListView,ListView,TextView) which prints me INBOX, Send and in TextView it prints some useful information.

现在,如果我想点击任何项目的ListView ,它会打开短信管理器,它会充满了 phoneNumber的我点击了短信。

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(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 将返回所选项目的位置,但如果我使用 POS

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:

7月4日至2日:53:15.504:ERROR / SMSManager(328):值:android.content.ContentResolver$CursorWrapperInner@43e2b800

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);

请参阅用于文档的<一个href=\"http://developer.android.com/reference/android/content/ContentResolver.html#query%28android.net.Uri,%20java.lang.String%5B%5D,%20java.lang.String,%20java.lang.String%5B%5D,%20java.lang.String%29\"相对=nofollow> ContentResolver.query 。

这篇关于Android的:问题OnItemClickListener的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆