I'm extremely new to Java and Android development and recently did a quick skim over the documentation to begin learning Android development. These should be very basic clarity-questions, but I can't find the right place to search to get the answer.
I was hopping I could get some clarification on the syntax in this android tutorial:
All of the private variables are declared at the top of the class and prefixed with "m". Why is this? What does the m-prefix imply?
private DrawerLayout mDrawerLayout;
When these m-prefixed variables are declared inside of the method, why are their parent objects written with a parenthesis?
mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
I'm a bit confused over this because I see objects being instantiated with the new
keyword. Is this different from what's going on above?
And my last question, why are there arrows >< wrapped around String
new ArrayAdapter<String>
Here's the full example code
public class MainActivity extends Activity {
private String[] mPlanetTitles;
private DrawerLayout mDrawerLayout;
private ListView mDrawerList;
...
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mPlanetTitles = getResources().getStringArray(R.array.planets_array);
mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
mDrawerList = (ListView) findViewById(R.id.left_drawer);
// Set the adapter for the list view
mDrawerList.setAdapter(new ArrayAdapter<String>(this,
R.layout.drawer_list_item, mPlanetTitles));
// Set the list's click listener
mDrawerList.setOnItemClickListener(new DrawerItemClickListener());
...
}
}