以下代碼顯示一個錯誤味精,構造函數ArrayAdapter <String>(SmsActivity,int,SmsActivity.SmsReceived)未定義?
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();
}
}
}
}
}
**對不起,因爲我這些東西真的太新了,所以希望你可以直接編輯我的代碼,以便我可以看到你想說的。我真的很抱歉,如果它確實給你帶來了很多負擔...