Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>There is one simple way you can consolidate the entire thing, is by using a <code>BaseActivity</code> class which has all the common stuff like your slide menu setup related code. Now all activities which require the sliding menu feature can extend <code>BaseActivity</code> instead of <code>SlidingActivity</code></p> <p>Something like this:</p> <pre><code>public class BaseActivity extends SlidingActivity implements OnItemClickListener{ public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); //content view is set by the activity which extends BaseActivity setBehindContentView(R.layout.list); getSlidingMenu().setBehindOffsetRes(R.dimen.actionbar_home_width); //Button btn = (Button) findViewById(R.id.button); //ListClass l=new ListClass(getApplicationContext()); ListView lv=(ListView) findViewById(R.id.lvname); String[] values = new String[] { "Android", "iPhone", "WindowsMobile", "Blackberry", "WebOS", "Ubuntu", "Windows7", "Max OS X", "Linux", "OS/2" }; ArrayAdapter&lt;String&gt; adapter = new ArrayAdapter&lt;String&gt;(this, android.R.layout.simple_list_item_1, android.R.id.text1, values); // Assign adapter to ListView lv.setAdapter(adapter); lv.setOnItemClickListener(new OnItemClickListener() { /* * (non-Javadoc) * * @see * android.widget.AdapterView.OnItemClickListener#onItemClick * (android.widget.AdapterView, android.view.View, int, long) */ @Override public void onItemClick(AdapterView&lt;?&gt; parent, View view, int position, long id) { switch(arg2){ case 1: Intent myIntent = new Intent(this,TestClass.class); startActivity(myIntent); break; } } }); getActionBar().setHomeButtonEnabled(true); } @Override public boolean onCreateOptionsMenu(Menu menu) { MenuInflater inflater = getMenuInflater(); inflater.inflate(R.menu.main, menu); return true; } @Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case android.R.id.home: // app icon in action bar clicked; go home toggle(); return true; default: return super.onOptionsItemSelected(item); } } } </code></pre> <p>And your example activity looks something like this:</p> <pre><code>public class ExampleActivity2 extends BaseActivity{ public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); Button btn = (Button) findViewById(R.id.button); } } </code></pre> <p><strong>Always remember to call super or else you will get runtime exceptions</strong></p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload