N
N
nikita_chiru2016-06-03 19:48:15
Android
nikita_chiru, 2016-06-03 19:48:15

What kind of harmful thing is the swipe menu?

I made a swipe menu according to this example, everything works
www.anjadev.com/all/programming/android_developmen...
as soon as I added the Navigation drawer, when I click on the button from the swipe menu, the application crashes .... help whoever can
///
\ \\\\\\\\\\\\\\\
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("Philadelphia Classic ", 169, R.drawable.filadelfia));
cold.add(new ListData("Rainbow", 169, R.drawable.raduga));
cold.add(new ListData("Double Strike", 209, R.drawable.dvoi));
cold.add(new ListData("Chickenhot", 209, R.drawable.chikenhot));
cold.add(new ListData("Lava", 219, R.drawable.lava));
cold.add(new ListData("Philadelphia Premium", 240, R.drawable.filadpro));
cold.add(new ListData("Creamy Salmon", 169, R.drawable.slivslos));
cold.add(new ListData("Saiman", 240, R.drawable.saiman));
cold.add(new ListData("Vegetarian",149 , R.drawable.veg));
cold.add(new ListData("Yasai Roll", 159, R.drawable.yasai));
cold.add(new ListData("California", 169, R.drawable.california));
cold.add(new ListData("Caviar Philadelphia", 189, R.drawable.vikrefill));
cold.add(new ListData("California cheese", 209, R.drawable.californiachis));
cold.add(new ListData("California Shrimp", 209, R.drawable.californiaskrev));
cold.add(new ListData("Alcapone", 210, R.drawable.alkap));
cold.add(new ListData("Jazz Blues", 210, R.drawable.jazbluz));
cold.add(new ListData("Chuka", 210, R.drawable.chuka));
cold.add(new ListData("Kiota", 220, R.drawable.kiota));
cold.add(new ListData("Dakota", 214, R.drawable.dakota));
cold.add(new ListData("Volcano", 219, R.drawable.vulkan));
cold.add(new ListData("Spicey Abi", 220, R.drawable.spaisiebi));
cold.
cold.add(new ListData("Okinawa", 220, R.drawable.okinava));
cold.add(new ListData("Eel with mushrooms", 230, R.drawable.ugorsgribami));
cold.add(new ListData("Roll Akori", 239, R.drawable.rollakori));
cold.add(new ListData("Philadelphia Royal", 240, R.drawable.fillroial));
cold.add(new ListData("Cream Cheese", 240, R.drawable.crem));
cold.add(new ListData("Green Roll", 179, R.drawable.green));
cold.add(new ListData("Bonito", 189, R.drawable.bonito));
cold.add(new ListData("Spicy Tuna", 199, R.drawable.ostristuncom));
cold.add(new ListData("Caesar maki", 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 shown 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 +"__"+"price"+"__"+ 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.
} 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());
}
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
G
GavriKos, 2016-06-03
@GavriKos

You would have posted a log instead of a canvas of code.
And yes - the code must be enclosed in a tag so that it is readable.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question