Сделал свайп меню по этому примеру , всё работает
www.anjadev.com/all/programming/android_developmen...
как только добавил Navigation drawer ,при нажатии на кнопку из свайп меню приложение вылетает .... помогите кто чем сможет
///
\\\\\\\\\\\\\\\\
import android.content.ContentValues;
import android.content.Intent;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.util.Log;
import android.util.TypedValue;
import android.view.LayoutInflater;
import android.view.View;
import android.support.design.widget.NavigationView;
import android.support.v4.view.GravityCompat;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.ActionBarDrawerToggle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.Toast;
import java.util.ArrayList;
import java.util.List;
public class Cold extends AppCompatActivity
implements NavigationView.OnNavigationItemSelectedListener {
DBHelper dbHelper;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_cold);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
SwipeMenuListView listView = (SwipeMenuListView) findViewById(R.id.listView);
List cold = new ArrayList<>();
cold.add(new ListData("Филадельфия Classic ", 169, R.drawable.filadelfia));
cold.add(new ListData("Радуга", 169, R.drawable.raduga));
cold.add(new ListData("Двойной удар", 209, R.drawable.dvoi));
cold.add(new ListData("Чикен хот", 209, R.drawable.chikenhot));
cold.add(new ListData("Лава", 219, R.drawable.lava));
cold.add(new ListData("Филадельфия премиум", 240, R.drawable.filadpro));
cold.add(new ListData("Сливочный с лососем", 169, R.drawable.slivslos));
cold.add(new ListData("Сайман", 240, R.drawable.saiman));
cold.add(new ListData("Вегетарианский",149 , R.drawable.veg));
cold.add(new ListData("Ясай ролл", 159, R.drawable.yasai));
cold.add(new ListData("Калифорния", 169, R.drawable.california));
cold.add(new ListData("Филадельфия в икре", 189, R.drawable.vikrefill));
cold.add(new ListData("Чикен ролл", 209, R.drawable.chikenroll));
cold.add(new ListData("Калифорния чиз", 209, R.drawable.californiachis));
cold.add(new ListData("Калифорния с креветкой", 209, R.drawable.californiaskrev));
cold.add(new ListData("Алькапоне", 210, R.drawable.alkap));
cold.add(new ListData("Джаз блюз", 210, R.drawable.jazbluz));
cold.add(new ListData("Чука", 210, R.drawable.chuka));
cold.add(new ListData("Киота", 220, R.drawable.kiota));
cold.add(new ListData("Дакота", 214, R.drawable.dakota));
cold.add(new ListData("Вулкан", 219, R.drawable.vulkan));
cold.add(new ListData("Спайси Эби", 220, R.drawable.spaisiebi));
cold.add(new ListData("Вендетта", 230, R.drawable.vendeta));
cold.add(new ListData("Окинава", 220, R.drawable.okinava));
cold.add(new ListData("Угорь с грибам", 230, R.drawable.ugorsgribami));
cold.add(new ListData("Ролл акори", 239, R.drawable.rollakori));
cold.add(new ListData("Филадельфия роял", 240, R.drawable.fillroial));
cold.add(new ListData("Крем чиз", 240, R.drawable.crem));
cold.add(new ListData("Грин ролл", 179, R.drawable.green));
cold.add(new ListData("Бонито", 189, R.drawable.bonito));
cold.add(new ListData("Острый с тунцом", 199, R.drawable.ostristuncom));
cold.add(new ListData("Цезарь маки", 209, R.drawable.cezarmakki));
final CustomArrayAdapter adapter = new CustomArrayAdapter(this, R.layout.item, cold);
listView.setAdapter(adapter);
SwipeMenuCreator creator = new SwipeMenuCreator() {
@Override
public void create(SwipeMenu menu) {
//create an action that will be showed on swiping an item in the list
SwipeMenuItem item1 = new SwipeMenuItem(
getApplicationContext());
item1.setBackground(new ColorDrawable(Color.DKGRAY));
// set width of an option (px)
item1.setWidth(dp2px(60));
item1.setIcon(R.drawable.ic_action_corz);
item1.setTitleSize(18);
item1.setTitleColor(Color.WHITE);
menu.addMenuItem(item1);
SwipeMenuItem item2 = new SwipeMenuItem(
getApplicationContext());
// set item background
item2.setBackground(new ColorDrawable(Color.RED));
item2.setWidth(dp2px(60));
item2.setIcon(R.drawable.ic_action_like);
item2.setTitleSize(18);
item2.setTitleColor(Color.WHITE);
menu.addMenuItem(item2);
SwipeMenuItem item3 = new SwipeMenuItem(
getApplicationContext());
// set item background
item3.setBackground(new ColorDrawable(Color.YELLOW));
item3.setWidth(dp2px(60));
item3.setIcon(R.drawable.ic_action_like);
item3.setTitleSize(18);
item3.setTitleColor(Color.WHITE);
menu.addMenuItem(item3);
}
};
//set MenuCreator
listView.setMenuCreator(creator);
// set SwipeListener
listView.setOnSwipeListener(new SwipeMenuListView.OnSwipeListener() {
@Override
public void onSwipeStart(int position) {
// swipe start
}
@Override
public void onSwipeEnd(int position) {
// swipe end
}
});
listView.setOnMenuItemClickListener(new SwipeMenuListView.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(int position, SwipeMenu menu, int index) {
String value3 = adapter.getItem(position).title;
int value2 = adapter.getItem(position).price;
SQLiteDatabase database = dbHelper.getWritableDatabase();
ContentValues contentValues = new ContentValues();
switch (index) {
case 0:
contentValues.put(DBHelper.KEY_NAME, value3);
contentValues.put(DBHelper.KEY_PRICE, value2);
database.insert(DBHelper.TABLE_IZBRANNOE, null, contentValues);;
Toast.makeText(getApplicationContext(), "Action 2 for " + value3 +"__"+"цена"+"__"+ value2, Toast.LENGTH_SHORT ).show();
break;
case 1:
Cursor cursor = database.query(DBHelper.TABLE_IZBRANNOE, null, null, null, null, null, null);
if (cursor.moveToFirst()) {
int idIndex = cursor.getColumnIndex(DBHelper.KEY_ID);
int nameIndex = cursor.getColumnIndex(DBHelper.KEY_NAME);
int priceIndex = cursor.getColumnIndex(DBHelper.KEY_PRICE);
do {
Log.d("mLog", "ID = " + cursor.getInt(idIndex) +
", name = " + cursor.getString(nameIndex) +
", price = " + cursor.getString(priceIndex));
} while (cursor.moveToNext());
} else
Log.d("mLog","0 rows");
cursor.close();
break;
case 2:
database.delete(DBHelper.TABLE_IZBRANNOE, null, null);
break;
}
return false;
}
});
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
drawer.setDrawerListener(toggle);
toggle.syncState();
NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
navigationView.setNavigationItemSelectedListener(this);
}
@Override
public void onBackPressed() {
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
if (drawer.isDrawerOpen(GravityCompat.START)) {
drawer.closeDrawer(GravityCompat.START);
} else {
super.onBackPressed();
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu)
{
return false;
}
@SuppressWarnings("StatementWithEmptyBody")
@Override
public boolean onNavigationItemSelected(MenuItem item) {
// Handle navigation view item clicks here.
int id = item.getItemId();
if (id == R.id.nav_camera) {
// Handle the camera action
} else if (id == R.id.nav_gallery) {
} else if (id == R.id.nav_slideshow) {
} else if (id == R.id.nav_manage) {
} else if (id == R.id.nav_share) {
} else if (id == R.id.nav_send) {
}
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
drawer.closeDrawer(GravityCompat.START);
return true;
}
private int dp2px(int dp) {
return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dp,
getResources().getDisplayMetrics());
}
}