My project is use to receive SMS and display in a list.
Error occurs in following line of code
setListAdapter(new ArrayAdapter<String>(this, R.layout.main,str));
Due to ListActivity is not define in code below. However BroadcastReceiver required for method to receive SMS.
public class SmsReceiver extends BroadcastReceiver{
So, question is how to define both superclass in one java codes? Full java code is provided below:
package net.eg.app;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.app.ListActivity;
import android.telephony.SmsMessage;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;
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();
str += " :";
str += msgs[i].getMessageBody().toString();
str += "\n";
}
//---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
});
}
}
}
If by “define both superclass” you mean, extending more than one class then the simple answer is NO. Java does not support multiple inheritance. You should rethink your whole approach.
But you can do something like:
Also you can find more on multiple inheritance and “work-arounds” if you really needed. Just search on Google.
Hope that helps. If that did not help at all, then my apologies for misunderstanding your question.