在此应用程序中,当选择左侧导航栏或操作栏“新建列表”按钮时,会弹出一个警告对话框。警报对话框包含已创建项目的列表,因此您可以选择项目或创建项目。根据SQLite数据库中的内容填充项目列表。
有一点背景,主要活动有一个列表视图,显示这些相同项目的列表。目前,我可以从列表中选择项目,传递行数据,启动新活动,并使用所选项目中的数据将新活动中的文本视图填充到另一个活动中。
我需要在这里做同样的事情,但是从警报对话框列表视图中。它需要将项目名称传递给新启动的New List活动,并在操作栏或文本视图中显示它。
正如您在左侧导航栏的警告对话框中看到的那样,如果选择了位置2,则会出现警告对话框,并从数据库中填充列表。 displayToastForId(idInDB);工作,所以我知道我正在访问数据。当我尝试使用passListName(idInDB);它没有做任何事情。
我现在已经搜索并试验了一周。我究竟做错了什么?
Intent i;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
getSupportActionBar().setTitle("Home");
mDrawerList = (ListView)findViewById(R.id.navList);
mDrawerLayout = (DrawerLayout)findViewById(R.id.drawer_layout);
addDrawerItems();
setupDrawer();
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setHomeButtonEnabled(true);
registerListClickCallbackMainList();
try {
openDB();
populateProjects();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
i = new Intent(this, NewList.class);
}
//Starting New List activity and passing project name to edit text
public void passListName(long idInDB) throws SQLException {
Cursor cursor = NewProjectDatabaseAdapter.getListInfo(idInDB);
if (cursor.moveToFirst()) {
String projectName = cursor.getString(NewProjectDatabaseAdapter.COL_LIST_PROJECT_NAME);
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
i.putExtra("project_name", String.valueOf(projectName));
startActivity(i);
}
cursor.close();
}
//end of passing data
/////////////////toast for item clicked on listview////////////////////
//gets all data from row clicked
public void displayToastForId(long idInDB) throws SQLException {
Cursor cursor = NewProjectDatabaseAdapter.getProjectInfo(idInDB);
if (cursor.moveToFirst()) {
long idDB = cursor.getLong(NewProjectDatabaseAdapter.COL_PROJECT_ROWID);
String project_name = cursor.getString(NewProjectDatabaseAdapter.COL_PROJECT_NAME);
String address = cursor.getString(NewProjectDatabaseAdapter.COL_PROJECT_ADDRESS);
String job_number = cursor.getString(NewProjectDatabaseAdapter.COL_PROJECT_JOB_NUMBER);
String site_contact = cursor.getString(NewProjectDatabaseAdapter.COL_PROJECT_SITE_CONTACT);
String phone = cursor.getString(NewProjectDatabaseAdapter.COL_PROJECT_SITE_CONTACT_PHONE_NUMBER);
String email = cursor.getString(NewProjectDatabaseAdapter.COL_PROJECT_SITE_CONTACT_EMAIL_ADDRESS);
String message = "ID: " + idDB + "\n"
+ "Size: " + project_name + "\n"
+ "Type: " + address + "\n"
+ "Length: " + job_number + "\n"
+ "Color: " + site_contact + "\n"
+ "Color: " + phone + "\n"
+ "Cut: " + email;
Toast.makeText(MainActivity.this, message, Toast.LENGTH_LONG).show();
}
cursor.close();
}
/////////////////////end of toast for item clicked on listview//////////////////////
////////////////////////////////////////////////////////////////
//This code adds the drawer items to the left navigation bar.
///////////////////////////////////////////////////////////////
public void addDrawerItems() {
String[] osArray = { "Home", "Search", "New List", "New Project", "Reminders", "Preferences", "Help" };
mAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, osArray);
mDrawerList.setAdapter(mAdapter);
mDrawerList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, final long id) {
DrawerLayout mDrawerLayout;
mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
if (position == 0){
//Do nothing if left nav
}
if (position == 1){
Intent myIntent = new Intent(view.getContext(), Search.class);
startActivityForResult(myIntent, 0);
mDrawerLayout.closeDrawers();
finish();
}
if (position == 2){
AlertDialog.Builder alertDialog = new AlertDialog.Builder(MainActivity.this);
LayoutInflater inflater = getLayoutInflater();
View convertView = inflater.inflate(R.layout.new_list_custom_dialog, null);
alertDialog.setView(convertView);
alertDialog.setPositiveButton("Create", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface alert, int which) {
//Do something here on click
startActivity(new Intent(MainActivity.this, NewProject.class));
finish();
alert.dismiss();
}
});
alertDialog.setTitle("Select a Project");
try{
openDB();
} catch (SQLException e){
e.printStackTrace();
}
//Testing fetching projects info from database to populate list
Cursor cursor1 = NewProjectDatabaseAdapter.fetchProjectName();
startManagingCursor(cursor1);
///setup mapping from cursor to view fields//////
String[] fromDatabase = new String[]
{NewProjectDatabaseAdapter.KEY_PROJECT_NAME};
int[] toList = new int[]
{R.id.alert_dialog_project_name};
////create adapter to map columns of database to rows in listview
@SuppressWarnings("deprecation") final
SimpleCursorAdapter myCursorAdapter1 =
new SimpleCursorAdapter(
MainActivity.this,
R.layout.main_activity_projects_alert_dialog_list_item,
cursor1,
fromDatabase,
toList,
0
);
ListView lv = (ListView) convertView.findViewById(R.id.listView1);
lv.setAdapter(myCursorAdapter1);
alertDialog.show();
lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View viewClicked,
int position, long idInDB) {
try {
displayToastForId(idInDB);
//passListName(idInDB);
} catch (SQLException e) {
e.printStackTrace();
}
}
});
}
if (position == 3){
Intent myIntent = new Intent(view.getContext(), NewProject.class);
startActivityForResult(myIntent, 0);
mDrawerLayout.closeDrawers();
finish();
}
if (position == 4){
Intent myIntent = new Intent(view.getContext(), Reminders.class);
startActivityForResult(myIntent, 0);
mDrawerLayout.closeDrawers();
finish();
}
if (position == 5){
}
if (position == 6){
}
if (position == 7){
}
if (position == 8){
}
}
});
}
//End of adding items to left nav bar////////////////////////////////////////
答案 0 :(得分:0)
我找到了似乎有效的解决方案。
以下是我现在的两项工作活动。
MainActivity.java
public class MainActivity extends ActionBarActivity implements AdapterView.OnItemSelectedListener{
NewProjectDatabaseAdapter db;
public final static String ID_EXTRA="com.gofor.gofor._ID";
private ListView mDrawerList;
private DrawerLayout mDrawerLayout;
private ArrayAdapter<String> mAdapter;
private ActionBarDrawerToggle mDrawerToggle;
Intent i;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
getSupportActionBar().setTitle("Home");
mDrawerList = (ListView)findViewById(R.id.navList);
mDrawerLayout = (DrawerLayout)findViewById(R.id.drawer_layout);
addDrawerItems();
setupDrawer();
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setHomeButtonEnabled(true);
registerListClickCallbackMainList();
try {
openDB();
populateProjects();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
i = new Intent(this, NewList.class);
}
public View.OnClickListener listener = new View.OnClickListener() {
@Override
public void onClick(View arg0) {
}
};
//The method populates the current projects listview with the name of the project from the projects table
public void populateProjects() throws SQLException {
try{
openDB();
} catch (SQLException e){
e.printStackTrace();
}
Cursor cursor1 = NewProjectDatabaseAdapter.fetchProjectName();
startManagingCursor(cursor1);
///setup mapping from cursor to view fields//////
String[] fromDatabase = new String[]
{NewProjectDatabaseAdapter.KEY_PROJECT_NAME};
int[] toList = new int[]
{R.id.project_name};
////create adapter to map columns of database to rows in listview//////
@SuppressWarnings("deprecation") final
SimpleCursorAdapter myCursorAdapter1 =
new SimpleCursorAdapter(
this,
R.layout.main_activity_projects_list_item,
cursor1,
fromDatabase,
toList,
0
);
final ListView myList = (ListView) findViewById(R.id.projectListView);
myList.setAdapter(myCursorAdapter1);
}
//End of populating projects list
/////////////////call back method for when list item is clicked from main activity main list////////////////////////////////
public void registerListClickCallbackMainList() {
ListView myList = (ListView) findViewById(R.id.projectListView);
myList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View viewClicked,
int position, long idInDB) {
try {
displayToastForId(idInDB);
passProjectInfo(idInDB);
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
});
}
//////////////////////end of call back method for when the list item is clicked///////////////////////
/////////////////toast for item clicked on listview////////////////////
//gets all data from row clicked
public void displayToastForId(long idInDB) throws SQLException {
Cursor cursor = NewProjectDatabaseAdapter.getProjectInfo(idInDB);
if (cursor.moveToFirst()) {
long idDB = cursor.getLong(NewProjectDatabaseAdapter.COL_PROJECT_ROWID);
String project_name = cursor.getString(NewProjectDatabaseAdapter.COL_PROJECT_NAME);
String address = cursor.getString(NewProjectDatabaseAdapter.COL_PROJECT_ADDRESS);
String job_number = cursor.getString(NewProjectDatabaseAdapter.COL_PROJECT_JOB_NUMBER);
String site_contact = cursor.getString(NewProjectDatabaseAdapter.COL_PROJECT_SITE_CONTACT);
String phone = cursor.getString(NewProjectDatabaseAdapter.COL_PROJECT_SITE_CONTACT_PHONE_NUMBER);
String email = cursor.getString(NewProjectDatabaseAdapter.COL_PROJECT_SITE_CONTACT_EMAIL_ADDRESS);
String message = "ID: " + idDB + "\n"
+ "Project: " + project_name + "\n"
+ "Address: " + address + "\n"
+ "Job#: " + job_number + "\n"
+ "Site Contact: " + site_contact + "\n"
+ "Phone: " + phone + "\n"
+ "Email: " + email;
Toast.makeText(MainActivity.this, message, Toast.LENGTH_LONG).show();
}
cursor.close();
}
/////////////////////end of toast for item clicked on listview//////////////////////
/////////////////starts new list activity and passes project name and rowid
public void passProjectName(long idInDB) throws SQLException {
Cursor cursor = NewProjectDatabaseAdapter.getProjectInfo(idInDB);
if (cursor.moveToFirst()) {
long idDB = cursor.getLong(NewProjectDatabaseAdapter.COL_PROJECT_ROWID);
String project_name = cursor.getString(NewProjectDatabaseAdapter.COL_PROJECT_NAME);
i.putExtra("project_rowid", String.valueOf(idDB));
i.putExtra("list_project_name", String.valueOf(project_name));
startActivity(i);
}
cursor.close();
}
/////////////////////end of new list activity and passing projet name and rowid//////////////////////
////////////////////////////////////////////////////////////////
//This code adds the drawer items to the left navigation bar.
///////////////////////////////////////////////////////////////
public void addDrawerItems() {
String[] osArray = { "Home", "Search", "New List", "New Project", "Reminders", "Preferences", "Help" };
mAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, osArray);
mDrawerList.setAdapter(mAdapter);
mDrawerList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, final long id) {
DrawerLayout mDrawerLayout;
mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
if (position == 0){
//Do nothing if left nav
}
if (position == 1){
Intent myIntent = new Intent(view.getContext(), Search.class);
startActivityForResult(myIntent, 0);
mDrawerLayout.closeDrawers();
finish();
}
if (position == 2){
AlertDialog.Builder alertDialog = new AlertDialog.Builder(MainActivity.this);
final LayoutInflater inflater = getLayoutInflater();
View convertView = inflater.inflate(R.layout.new_list_custom_dialog, null);
alertDialog.setView(convertView);
alertDialog.setPositiveButton("Create", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface alert, int which) {
//Do something here on click
startActivity(new Intent(MainActivity.this, NewProject.class));
finish();
alert.dismiss();
}
});
alertDialog.setTitle("Select a Project");
try{
openDB();
} catch (SQLException e){
e.printStackTrace();
}
//Testing fetching projects info from database to populate list
Cursor cursor1 = NewProjectDatabaseAdapter.fetchProjectName();
startManagingCursor(cursor1);
///setup mapping from cursor to view fields//////
String[] fromDatabase = new String[]
{NewProjectDatabaseAdapter.KEY_PROJECT_NAME};
int[] toList = new int[]
{R.id.alert_dialog_project_name};
////create adapter to map columns of database to rows in listview
@SuppressWarnings("deprecation") final
SimpleCursorAdapter myCursorAdapter1 =
new SimpleCursorAdapter(
MainActivity.this,
R.layout.main_activity_projects_alert_dialog_list_item,
cursor1,
fromDatabase,
toList,
0
);
ListView lv = (ListView) convertView.findViewById(R.id.listView1);
lv.setAdapter(myCursorAdapter1);
alertDialog.show();
lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View viewClicked,
int position, long idInDB) {
try {
//displayToastForId(idInDB);
passProjectName(idInDB);
} catch (SQLException e) {
e.printStackTrace();
}
}
});
}
if (position == 3){
Intent myIntent = new Intent(view.getContext(), NewProject.class);
startActivityForResult(myIntent, 0);
mDrawerLayout.closeDrawers();
finish();
}
if (position == 4){
Intent myIntent = new Intent(view.getContext(), Reminders.class);
startActivityForResult(myIntent, 0);
mDrawerLayout.closeDrawers();
finish();
}
if (position == 5){
}
if (position == 6){
}
if (position == 7){
}
if (position == 8){
}
}
});
}
//End of adding items to left nav bar////////////////////////////////////////
//Setting up the drawer for opening and closing the left nav bar
private void setupDrawer() {
mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout, R.string.drawer_open, R.string.drawer_close) {
/** Called when a drawer has settled in a completely open state. */
public void onDrawerOpened(View drawerView) {
super.onDrawerOpened(drawerView);
getSupportActionBar().setTitle("Choose One");
invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu()
}
/** Called when a drawer has settled in a completely closed state. */
public void onDrawerClosed(View view) {
super.onDrawerClosed(view);
//getSupportActionBar().setTitle(mActivityTitle);
invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu()
}
};
mDrawerToggle.setDrawerIndicatorEnabled(true);
mDrawerLayout.setDrawerListener(mDrawerToggle);
}
//End of setting up drawer for opening and closing the left nav bar
@Override
protected void onPostCreate(Bundle savedInstanceState) {
super.onPostCreate(savedInstanceState);
// Sync the toggle state after onRestoreInstanceState has occurred.
mDrawerToggle.syncState();
}
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
mDrawerToggle.onConfigurationChanged(newConfig);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
// Activate the navigation drawer toggle
if (mDrawerToggle.onOptionsItemSelected(item)) {
return true;
}
// TODO Auto-generated method stub
//This is the action bar new list icon
switch (item.getItemId()) {
case R.id.action_newlist:
//If the new list icon is selected bring up alert dialog and populates the list of projects inside.
AlertDialog.Builder alertDialog = new AlertDialog.Builder(MainActivity.this);
LayoutInflater inflater = getLayoutInflater();
View convertView = inflater.inflate(R.layout.new_list_custom_dialog, null);
alertDialog.setView(convertView);
alertDialog.setPositiveButton("Create", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface alert, int which){
//Do something here on click
startActivity(new Intent(MainActivity.this, NewProject.class));
finish();
alert.dismiss();
}
});
alertDialog.setTitle("Select a Project");
try{
openDB();
} catch (SQLException e){
e.printStackTrace();
}
//Testing fetching projects info from database to populate list
Cursor cursor1 = NewProjectDatabaseAdapter.fetchProjectName();
startManagingCursor(cursor1);
///setup mapping from cursor to view fields//////
String[] fromDatabase = new String[]
{NewProjectDatabaseAdapter.KEY_PROJECT_NAME};
int[] toList = new int[]
{R.id.alert_dialog_project_name};
////create adapter to map columns of database to rows in listview//////
@SuppressWarnings("deprecation") final
SimpleCursorAdapter myCursorAdapter1 =
new SimpleCursorAdapter(
this,
R.layout.main_activity_projects_alert_dialog_list_item,
cursor1,
fromDatabase,
toList,
0
);
ListView lv = (ListView) convertView.findViewById(R.id.listView1);
lv.setAdapter(myCursorAdapter1);
//on item click listener for the alert dialog listview of projects
lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View viewClicked,
int position, long idInDB) {
// try {
// passListName(idInDB);
// } catch (SQLException e) {
// // TODO Auto-generated catch block
// e.printStackTrace();
// }
}
});
alertDialog.show();
break;
default:
break;
}
//End of action bar new list icon selection.
switch (item.getItemId()) {
case R.id.action_search:
Toast.makeText(this, "Search", Toast.LENGTH_SHORT).show();
break;
default:
break;
}
return super.onOptionsItemSelected(item);
}
//End of on options item selected///////////////////////////////////////////////////////////////
//This method creates a new instance of open database method in NewProjectDatabaseAdapter.java
private void openDB() throws SQLException {
db = new NewProjectDatabaseAdapter(this);
NewProjectDatabaseAdapter.open();
}
//End of open database method
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
}
}
NewList.java
public class NewList extends ActionBarActivity implements AdapterView.OnItemSelectedListener, View.OnClickListener {
Button Done, Cancel;
EditText sqlNewListProjectName, sqlNewListName, sqlNewListDate, sqlNewListTime,
sqlNewListMethod, sqlNewListNotes;
private ListView mDrawerList;
private DrawerLayout mDrawerLayout;
private ArrayAdapter<String> mAdapter;
private ActionBarDrawerToggle mDrawerToggle;
private String mActivityTitle;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.new_list);
Done = (Button) findViewById(R.id.new_list_done_button);
Cancel = (Button) findViewById(R.id.new_list_cancel_button);
//sqlNewListProjectName = (EditText) findViewById(R.id.new_list_project_name);
sqlNewListName = (EditText) findViewById(R.id.new_list_list_name);
sqlNewListDate = (EditText) findViewById(R.id.new_list_date);
sqlNewListTime = (EditText) findViewById(R.id.new_list_time);
sqlNewListNotes = (EditText) findViewById(R.id.new_list_notes);
Done.setOnClickListener(this);
Cancel.setOnClickListener(this);
getSupportActionBar().setTitle("New List");
mDrawerList = (ListView)findViewById(R.id.navList);
mDrawerLayout = (DrawerLayout)findViewById(R.id.drawer_layout);
mActivityTitle = getTitle().toString();
addDrawerItems();
setupDrawer();
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setHomeButtonEnabled(true);
String project_rowid = getIntent().getExtras().getString("project_rowid");
String project_name = getIntent().getExtras().getString("list_project_name");
TextView tv1 = (TextView) findViewById(R.id.new_list_project_name);
tv1.setText(project_name);
Toast.makeText(NewList.this, project_rowid, Toast.LENGTH_LONG).show();
}
@Override
public void onClick(View view) {
//TODO Auto generated method stub
switch (view.getId()) {
case R.id.new_list_done_button:
boolean didItWork = true;
try {
//This is pulling the text entered from the text fields for the new project, creating strings
// from them and entering them into the projects table
String projectName = sqlNewListProjectName.getText().toString();
String listName = sqlNewListName.getText().toString();
String listDate = sqlNewListDate.getText().toString();
String listTime = sqlNewListTime.getText().toString();
//String listMethod = sqlNewListMethod.getText().toString();
String listNotes = sqlNewListNotes.getText().toString();
NewProjectDatabaseAdapter entry = new NewProjectDatabaseAdapter(NewList.this);
NewProjectDatabaseAdapter.open();
entry.createEntry(projectName, listName, listDate, listTime,
//listMethod,
listNotes);
entry.close();
} catch (Exception e ){
didItWork = false;
String error = e.toString();
Dialog d = new Dialog(this);
d.setTitle("Nope!");
TextView tv = new TextView(this);
tv.setText(error);
d.setContentView(tv);
d.show();
}finally {
if (didItWork) {
Toast.makeText(this, "List Created!" + '\n' + '\n' + sqlNewListName.getText().toString(), Toast.LENGTH_LONG).show();
startActivity(new Intent(NewList.this, Search.class));
}
}
break;
case R.id.new_list_cancel_button:
AlertDialog.Builder builder = new AlertDialog.Builder(NewList.this);
builder.setMessage("Cancel and go Home?")
.setCancelable(false)
.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
startActivity(new Intent(NewList.this, MainActivity.class));
// Intent myIntent = new Intent(view.getContext(), MainActivity.class);
// startActivityForResult(myIntent, 0);
//call this when ready to exit dialog
//NewProject.this.finish();
}
})
.setNegativeButton("No", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
//call this when ready to exit dialog
dialog.cancel();
}
});
AlertDialog alert = builder.create();
alert.show();
// Intent i = new Intent("com.gofor.gofor.SQLView");
// startActivity(i);
// break;
}
}
public View.OnClickListener listener = new View.OnClickListener() {
@Override
public void onClick(View arg0) {
}
};
private void addDrawerItems() {
String[] osArray = { "Home", "Search", "New List", "New Project", "Reminders", "Preferences", "Help" };
mAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, osArray);
mDrawerList.setAdapter(mAdapter);
mDrawerList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
DrawerLayout mDrawerLayout;
mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
if (position == 0) {
Intent myIntent = new Intent(view.getContext(), MainActivity.class);
startActivityForResult(myIntent, 0);
mDrawerLayout.closeDrawers();
finish();
}
if (position == 1) {
Intent myIntent = new Intent(view.getContext(), Search.class);
startActivityForResult(myIntent, 0);
mDrawerLayout.closeDrawers();
finish();
}
if (position == 2) {
//Do nothing
}
if (position == 3) {
Intent myIntent = new Intent(view.getContext(), NewProject.class);
startActivityForResult(myIntent, 0);
mDrawerLayout.closeDrawers();
finish();
}
if (position == 4) {
Intent myIntent = new Intent(view.getContext(), Reminders.class);
startActivityForResult(myIntent, 0);
mDrawerLayout.closeDrawers();
finish();
}
if (position == 5) {
}
if (position == 6) {
}
if (position == 7) {
}
if (position == 8) {
}
}
});
}
private void setupDrawer() {
mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout, R.string.drawer_open, R.string.drawer_close) {
/** Called when a drawer has settled in a completely open state. */
public void onDrawerOpened(View drawerView) {
super.onDrawerOpened(drawerView);
getSupportActionBar().setTitle("Choose One");
invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu()
}
/** Called when a drawer has settled in a completely closed state. */
public void onDrawerClosed(View view) {
super.onDrawerClosed(view);
//getSupportActionBar().setTitle(mActivityTitle);
invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu()
}
};
mDrawerToggle.setDrawerIndicatorEnabled(true);
mDrawerLayout.setDrawerListener(mDrawerToggle);
}
@Override
protected void onPostCreate(Bundle savedInstanceState) {
super.onPostCreate(savedInstanceState);
// Sync the toggle state after onRestoreInstanceState has occurred.
mDrawerToggle.syncState();
}
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
mDrawerToggle.onConfigurationChanged(newConfig);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
// Activate the navigation drawer toggle
if (mDrawerToggle.onOptionsItemSelected(item)) {
return true;
}
// TODO Auto-generated method stub
switch (item.getItemId()) {
case R.id.action_home:
Toast.makeText(this, "Home", Toast.LENGTH_SHORT).show();
startActivity(new Intent(NewList.this, MainActivity.class));
finish();
break;
default:
break;
}
switch (item.getItemId()) {
case R.id.action_search:
Toast.makeText(this, "Search", Toast.LENGTH_SHORT).show();
startActivity(new Intent(NewList.this, Search.class));
finish();
break;
default:
break;
}
return super.onOptionsItemSelected(item);
//noinspection SimplifiableIfStatement
// if (id == R.id.action_settings) {
// return true;
// }
}
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
}
}