以下代码显示错误消息,
setListAdapter(new ArrayAdapter<String>(this, R.layout.main,mSmsReceiver));
错误消息:构造函数 ArrayAdapter(SmsActivity, int, SmsActivity.SmsReceived) 未定义
下面提供了完整的代码。
我的问题:
- 我该如何解决这个错误?
而是使用 mSmsReceiver,我应该如何/如何修改以将 str(下方)中的消息显示到 ListView
str += "SMS from " + msgs[i].getOriginatingAddress();
完整代码:
import...
....
public class SmsActivity extends ListActivity {
private SmsReceived mSmsReceiver;
public SmsActivity(){
mSmsReceiver = new SmsReceived();
setListAdapter(new ArrayAdapter<String>(this, R.layout.main,mSmsReceiver));
ListView listView = getListView();
listView.setTextFilterEnabled(true);
//---method is call when listitem is clicked---
listView.setOnItemClickListener(new OnItemClickListener() {edit later});
}
private class SmsReceived extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent)
{
//---get the SMS message passed in---
Bundle bundle = intent.getExtras();
SmsMessage[] msgs = null;
String str = "";
if (bundle != null)
{
//---retrieve the SMS message received---
Object[] pdus = (Object[]) bundle.get("pdus");
msgs = new SmsMessage[pdus.length];
for (int i=0; i<msgs.length; i++){
msgs[i] = SmsMessage.createFromPdu((byte[])pdus[i]);
str += "SMS from " + msgs[i].getOriginatingAddress();
}
}
}
}
}
**对不起,因为我对这些东西真的太陌生了,所以希望你可以直接在我的代码中编辑,这样我就可以看到你想说什么。如果给你带来了很多负担,我真的很抱歉...