这个项目需要两个类。
BroadcastReceiver
(class)——接收短信;ListActivity
(class) — 显示 SMS;
因为setListAdapter()
方法需要定义ListActivity
(类),我的问题是我应该如何在下面的代码中定义这两个类?
import ....
public class SmsReceiver 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();
}
//----REQUIRE ListActivity(class) to define----//
// how should i define the class here???
//---display in list---
setListAdapter(new ArrayAdapter<String>(this, R.layout.main,str));
ListView listView = getListView();
listView.setTextFilterEnabled(true);
//---method is call when listitem is clicked---
listView.setOnItemClickListener(new OnItemClickListener() {
//described method
});
}
}