i am new to android development and i need help with going from a menu option to an activity. teh app crashes when i do this. Ive added the activity in the manifest file but it still doesnt work. cant seem to find the problem. The app crashes when i click on the select in the options menu but the log works fine.
In Tasb.java
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.select:
startActivity(new Intent(this, Select.class));
return true;
case R.id.log:
startActivity(new Intent(this, Log.class));
return true;
default:
return super.onOptionsItemSelected(item);
}
}
select_tasb.xml
<?xml version="1.0" encoding="utf-8"?>
<ListView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="10dp"
android:textSize="20sp">
</ListView>
In Select.java
public class Select extends Activity{
private ListView l;
static final String[] TASB = new String[] { "Tasbeeh-e-Fatima", "SubhanAllahi'l-adheem wa biHamdihi", "La Hawla wa la Quwatta illa Billah",
"La illaha ilAllah(u)", "SubhanAllah", "SubhanAllahi wa biHamdihi" };
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.select_tasb);
l = (ListView) findViewById(R.id.list);
l.setAdapter(new ArrayAdapter<String>(this, R.layout.list_item,TASB));
// ListView listView = getListView(); l.setTextFilterEnabled(true);
l.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
// When clicked, show a toast with the TextView text
Toast.makeText(getApplicationContext(),((TextView) view).getText(), Toast.LENGTH_SHORT).show();
Intent intent = null;
if(position == 0) {
intent = new Intent(Select.this,One.class);
} else if(position == 1) {
intent = new Intent(Select.this,One.class);
} else if(position == 2) {
intent = new Intent(Select.this,One.class);
}
startActivity(intent);
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// TODO Auto-generated method stub
return super.onCreateOptionsMenu(menu);
}
}
the One.java is a simple activity. Thank you in advance :)