i’m new here so still very blur with some certain things here.
& i’m a bit confuse with following codes.
public class SmsActivity extends ListActivity {
private String[] mSmsReceiver;
public SmsActivity(){
mSmsReceiver = new SmsReceived();
setListAdapter(new ArrayAdapter<String>(this, R.layout.main,mSmsReceiver));
my understanding: (should be wrong)
line 1: Class SmsActivity under a superclass ListActivity
line 2: i introduce a string array term name:mSmReceiver
line 3: calling method SmsActivity()
line 4: inside SmsActivity method, mSmsReceiver(a string array) call method SmsReceived
line 5: ArrayAdapter(in string form, loaded with the info. of mSmsReceiver) loaded into setListAdapter
My question:
- pls correct my understanding upon code above.
- line 5, what is
thisrefers to?
(i checked on internet & books, it always says context. but i’m totally no idea what is context exactly means, anyone can explain what is context refering here?)
full codes:
import...
....
public class SmsActivity extends ListActivity {
private String[] 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)
{..... }
}
}
Basically this is a definition of a class named
SmsActivity.You are right about line 1 and line 2. More precisely,
mSmReceiveris a private number of classSmsActivity.Line 3 should be the constructor which I am not sure because I’m not an android developer and I heard it use
onCreateinstead inActivity. But anyway it wouldn’t becalling the methodjust definition of it. The constructor will be used to initialize the class.And line 4
mSmsReceiver(a string array) call method SmsReceived. Not the case, it would beinitialize mSmsReceiver with an object, which is an instance of class SmsReceived.Line 5
thisrefers to the classSmsActivity. In classesthisalmost always refers to the class it’s in. And this provide a context so you can usethis.someMumberorthis.someFunction.