0

我怎样才能做到这一点。我尝试了很多方法。但我不能。我唯一做的和工作的就是用消息填充列表。但是当我触摸它时,它什么也没做。如何使列表可点击并获取消息?

这是我的代码列表。它读取收件箱

    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;


}

请帮助我在我的代码中添加什么。

4

1 回答 1

0

您需要为 lViewSMS 编写 OnItemClicklistener。

lViewSMS .setOnItemClickListener(new OnItemClickListener() {
    public void onItemClick(AdapterView<?> parent, View view,
        int position, long id) {
      // When clicked, show a toast with the TextView text
      Toast.makeText(getApplicationContext(), ((TextView) view).getText(),
          Toast.LENGTH_SHORT).show();
    }
  });

这是android链接ListView

于 2012-01-10T20:54:25.037 回答