Someone who can help me to fix this problem. (NoSuchMethodError) I really don't understand this error.
I have found similar problems on the web, but none of the posted solutions appear to work. Someone who can help me.
EDIT: I AM already working on Android Studio.
My screenshot
Other
package com.example.android.xxxxxxxxxxy;
import android.content.Intent;
import android.content.res.Configuration;
import android.media.MediaPlayer;
import android.net.Uri;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.ActionBarDrawerToggle;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ListView;
import android.widget.Toast;
import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.AdView;
public class MainActivity extends AppCompatActivity {
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.activity_main);
mDrawerList = (ListView)findViewById(R.id.navList);mDrawerLayout = (DrawerLayout)findViewById(R.id.drawer_layout);
mActivityTitle = getTitle().toString();
addDrawerItems();
setupDrawer();
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setHomeButtonEnabled(true);
AdView adView = (AdView) findViewById(R.id.adView);
AdRequest adRequest = new AdRequest.Builder()
.setRequestAgent("android_studio:ad_template").build();
// The firstbutton (song).
assert adView != null;
adView.loadAd(adRequest);
final MediaPlayer happy_birthday_to_me = MediaPlayer.create(this, R.raw.happy_birthday_to_me);
Button playsongmeow = (Button) this.findViewById(R.id.play_song_meow);
assert playsongmeow != null;
playsongmeow.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
happy_birthday_to_me.start();
}
});
// The secondbutton (song).
assert adView != null;
adView.loadAd(adRequest);
final MediaPlayer birthday = MediaPlayer.create(this, R.raw.birthday);
Button playsongmeoww = (Button) this.findViewById(R.id.play_song_meoww);
assert playsongmeoww != null;
playsongmeoww.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
birthday.start();
}
});
// The thirdbutton (song).
assert adView != null;
adView.loadAd(adRequest);
final MediaPlayer happy = MediaPlayer.create(this, R.raw.happy);
Button playsongmeowww = (Button) this.findViewById(R.id.play_song_meowww);
assert playsongmeowww != null;
playsongmeowww.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
happy.start();
}
});
// The fourthbutton (song).
assert adView != null;
adView.loadAd(adRequest);
final MediaPlayer original = MediaPlayer.create(this, R.raw.original);
Button playsongmeowwww = (Button) this.findViewById(R.id.play_song_meowwww);
assert playsongmeowwww != null;
playsongmeowwww.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
original.start();
}
});
}
private void addDrawerItems() {
String[] osArray = {"Songs", "Photos", "Videos", "About"};
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) {
Intent intent = new Intent(MainActivity.this, MainActivity.class);
startActivity(intent);
switch (position) {
case 0: //Log History
Intent MainActivity = new Intent(MainActivity.this, MainActivity.class);
startActivity(MainActivity);
break;
case 1: //Log History
Intent Photos = new Intent(MainActivity.this, Photos.class);
startActivity(Photos);
break;
case 2: //Log History
Intent Videos = new Intent(MainActivity.this, Videos.class);
startActivity(Videos);
break;
case 3: //Log History
Intent About = new Intent(MainActivity.this, About.class);
startActivity(About);
default:
}
}
});
}
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("List Menu");
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) {
// Inflate your main_menu into the menu.
int id = item.getItemId();
switch (id){
case R.id.about:
Intent About = new Intent(MainActivity.this, About.class);
startActivity(About);
break;
}
switch (id) {
case R.id.rate:
// Open this Uri.
Uri uri = Uri.parse("https://play.google.com/store/apps/details?id=com.exafmpflle.android.happybirthdayyyy&hl=en"); // missing 'http://' will cause crashed
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
startActivity(intent);
break;
}
switch (id){
case R.id.privacy:
// Open this Uri.
Uri uri = Uri.parse("https://docs.google.com/document/d/1DEBh3j3LG5WaF9nT9Gl2hpswa3yD-36MfPhVo3S_p08/edit"); // missing 'http://' will cause crashed
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
startActivity(intent);
break;
}
// Activate the navigation drawer toggle
if (mDrawerToggle.onOptionsItemSelected(item)) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
The error seems to be saying that one of the methods that you are overriding is nonexistent. Try double checking the spellings of the methods that you are overriding.
If this helps, please consider marking this post as an answer.
Related
The navigation bar open when swiped but menu items are unresponsive the nav header part updates as it should but if nav button is pressed the menu item button work properly in some devices it does not allow swiping to open the drawer
on swiping allowed devices it shows the option as selected but does not trigger it such problems are not occurring in the android studio emulator,i want the functions to work reguardless of opening way is swipe or drawer press if u want to try the app apk can be installed from here https://1drv.ms/u/s!AnbGL2sgNSjugQiS3ELexUrBfHQ8?e=XOanwt
Thank you in advance for takeing time to help
entire java activity code is as follows
package com.example.testing;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.os.Handler;
import android.view.MenuItem;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
import androidx.annotation.NonNull;
import androidx.appcompat.app.ActionBarDrawerToggle;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;
import androidx.cardview.widget.CardView;
import androidx.core.view.GravityCompat;
import androidx.drawerlayout.widget.DrawerLayout;
import com.bumptech.glide.Glide;
import com.google.android.material.navigation.NavigationView;
import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.auth.FirebaseUser;
import com.google.firebase.database.DataSnapshot;
import com.google.firebase.database.DatabaseError;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;
import com.google.firebase.database.ValueEventListener;
import java.net.URI;
public class Main2Activity extends AppCompatActivity {
//Navigation
DrawerLayout drawerLayout;
ActionBarDrawerToggle actionBarDrawerToggle;
NavigationView navigationView;
//CardView
CardView cdmarks,cdattendance,cdlibrary,cdidcard,cdrailwayconcession,cdquestion,cdcalendar;
FirebaseUser currentuser;
FirebaseAuth mAuth;
private DatabaseReference reference;
String userID,baronmail;
private static int splash=3000;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main2);
baronmail="baroncandy09#gmail.com";
currentuser=FirebaseAuth.getInstance().getCurrentUser();
reference= FirebaseDatabase.getInstance().getReference("users");
userID=currentuser.getUid();
//Navigation Page
navigationView = findViewById(R.id.navigation);
/*toolbar = findViewById(R.id.toolbar);*/
mAuth=FirebaseAuth.getInstance();
currentuser=mAuth.getCurrentUser();
drawerLayout = findViewById(R.id.drawer);
actionBarDrawerToggle = new ActionBarDrawerToggle(Main2Activity.this, drawerLayout,0, 0);
drawerLayout.addDrawerListener(actionBarDrawerToggle);
actionBarDrawerToggle.syncState();
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
updatenavhead();
//CardView FindViewByID
cdmarks = findViewById(R.id.marks);
cdattendance = findViewById(R.id.attend);
cdidcard = findViewById(R.id.idcard);
cdrailwayconcession = findViewById(R.id.railwayconcession);
cdlibrary = findViewById(R.id.library);
cdquestion = findViewById(R.id.question);
cdcalendar = findViewById(R.id.calendar);
//CardView marks
cdmarks.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Intent intent = new Intent(Main2Activity.this,MarksActivity.class);
startActivity(intent);
}
});
//CardView attendance
cdattendance.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Intent intent = new Intent(Main2Activity.this,AttendanceActivity.class);
startActivity(intent);
}
});
//CardView idcard
cdidcard.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Intent intent = new Intent(Main2Activity.this,IDActivity.class);
startActivity(intent);
}
});
//CardView railway concession
cdrailwayconcession.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Intent intent=new Intent(Main2Activity.this,RailwayConActivity.class);
startActivity(intent);
}
});
//CardView library
cdlibrary.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Intent intent = new Intent(Main2Activity.this,Library.class);
startActivity(intent);
}
});
//CardView Question
cdquestion.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Intent intent = new Intent(Main2Activity.this,QuestionActivity.class);
startActivity(intent);
}
});
//CardView Calendar
cdcalendar.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Intent intent = new Intent(Main2Activity.this,Calendaractivity.class);
startActivity(intent);
}
});
//Navigation Item selected event
}//outside saved instance like taught press and slide work
#Override
public boolean onOptionsItemSelected(#NonNull MenuItem menuItem){
if(actionBarDrawerToggle.onOptionsItemSelected(menuItem)){
navigationView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() {
public boolean onNavigationItemSelected(#NonNull MenuItem menuitem) {
switch (menuitem.getItemId()){
case R.id.Setting:
/*setting();*/
Toast.makeText(Main2Activity.this, "Display "+menuitem.getTitle(), Toast.LENGTH_SHORT).show();
Intent intent1 = new Intent(Main2Activity.this, com.example.testing.Setting.class);
startActivity(intent1);
break;
case R.id.Share:
Intent share= new Intent(Intent.ACTION_SEND);
share.setType("text/plain");
share.putExtra(Intent.EXTRA_TEXT,"install clgprg:\n "+"https://1drv.ms/u/s!AnbGL2sgNSjugQiS3ELexUrBfHQ8?e=XOanwt");
startActivity(Intent.createChooser(share,"share link via"));
break;
case R.id.makers:
Toast.makeText(Main2Activity.this, "Display "+menuitem.getTitle(), Toast.LENGTH_SHORT).show();
Intent intent4 = new Intent(Main2Activity.this, com.example.testing.madeby.class);
startActivity(intent4);
break;
case R.id.Feedback:
Intent intent2 =new Intent( Intent.ACTION_SEND);
intent2.putExtra(Intent.EXTRA_EMAIL,baronmail);
intent2.setType("message/rfc822");
startActivity(Intent.createChooser(intent2,"chose mail"));
break;
case R.id.logout:
//makes so have to log in again
SharedPreferences sharedPreferences= getSharedPreferences(Login.pref_name,0);
SharedPreferences.Editor editor= sharedPreferences.edit();
editor.putBoolean("hasloggedin",false);
editor.commit();
//logs out from firebase side
FirebaseAuth.getInstance().signOut();
Intent intent5= new Intent(Main2Activity.this,com.example.testing.Login.class);
startActivity(intent5);
Toast.makeText(Main2Activity.this, "Logged out..", Toast.LENGTH_SHORT).show();
finish();
}
return true;
}
});
}
return super.onOptionsItemSelected(menuItem);
}
//Navigation Function:-outside the main return idk but works
#Override
public void onBackPressed() {
if(drawerLayout.isDrawerOpen(GravityCompat.START)){
drawerLayout.closeDrawer(GravityCompat.START);
}
else{
super.onBackPressed();
}
}
public void updatenavhead()
{
navigationView = findViewById(R.id.navigation);
View headview=navigationView.getHeaderView(0);
TextView navusername=headview.findViewById(R.id.usernameplace);
ImageView navpfp=headview.findViewById(R.id.pfpback);
Glide.with(this).load(currentuser.getPhotoUrl()).into(navpfp);
reference.child(userID).addValueEventListener(new ValueEventListener()
{
#Override
public void onDataChange(#NonNull DataSnapshot snapshot)
{
RegisterUser reguser=snapshot.getValue(RegisterUser.class);
if (reguser!=null)
{
String FNAME= reguser.fname;
navusername.setText("Hello "+FNAME);
Glide.with(getApplicationContext()).load(reguser.getpfp()).centerCrop().into(navpfp);
}
}
#Override
public void onCancelled(#NonNull DatabaseError error) {
Toast.makeText(Main2Activity.this, "error", Toast.LENGTH_SHORT).show();
}
});
}
}
I have implemented navigation drawer on my mobile application and whenever i open the drawer and click on the drawer, the drawer closes itself. It used to work perfectly until I implemented another function and I am puzzled about how I should fix this.
Here's my main activity code. I am unable to navigate using the navigation drawer now.
package com.example.admin.calendlist;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.PorterDuff;
import android.graphics.drawable.Drawable;
import android.support.annotation.NonNull;
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.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.TextView;
import java.util.ArrayList;
public class MainActivity extends AppCompatActivity {
private DrawerLayout mDrawerLayout;
private ActionBarDrawerToggle mToggle;
DatabaseHelper dbHelper;
ArrayAdapter<String> mAdapter;
ListView lstTask;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mDrawerLayout = (DrawerLayout)findViewById(R.id.drawer);
mToggle = new ActionBarDrawerToggle(this,mDrawerLayout, R.string.open,R.string.close);
mDrawerLayout.addDrawerListener(mToggle);
mToggle.syncState();
dbHelper = new DatabaseHelper(this);
lstTask = (ListView)findViewById(R.id.lstTask);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
NavigationView nvDrawer = (NavigationView)findViewById(R.id.nav_view);
setupDrawerContent(nvDrawer);
loadTaskList();
}
private void loadTaskList() {
ArrayList<String> taskList = dbHelper.getTaskList();
if(mAdapter==null){
mAdapter = new ArrayAdapter<String>(this, R.layout.row,R.id.task_title,taskList);
lstTask.setAdapter(mAdapter);
}
else{
mAdapter.clear();
mAdapter.addAll(taskList);
mAdapter.notifyDataSetChanged();
}
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
if (mToggle.onOptionsItemSelected(item)){
return true;
}
{
switch (item.getItemId()) {
case R.id.action_add_task:
final EditText taskEditText = new EditText(this);
AlertDialog dialog = new AlertDialog.Builder(this)
.setTitle("Add New Task")
.setMessage("What do you want to do next?")
.setView(taskEditText)
.setPositiveButton("Add", new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialog, int which) {
String task = String.valueOf(taskEditText.getText());
dbHelper.insertNewTask(task);
loadTaskList();
}
})
.setNegativeButton("Cancel", null)
.create();
dialog.show();
}
switch (item.getItemId()) {
case R.id.td:
Intent newIntent = new Intent(this,MainActivity.class);
return true;
}
switch (item.getItemId()) {
case R.id.tt:
Intent newIntent = new Intent(this,Timetable.class);
return true;
}
switch (item.getItemId()) {
case R.id.ep:
Intent newIntent = new Intent(this,EventPage.class);
return true;
}
}
return super.onOptionsItemSelected(item);
}
private void selectItemDrawer(MenuItem item) {
int id = item.getItemId();
if (id ==R.id.ep) {
Intent newItent = new Intent (this, EventPage.class);
startActivity(newItent);
}
else if (id == R.id.td) {
Intent newIntent = new Intent (this,MainActivity.class);
startActivity(newIntent);
}
else if (id == R.id.tt) {
Intent newIntent = new Intent (this,Timetable.class);
startActivity(newIntent);
}
DrawerLayout drawer = findViewById(R.id.drawer);
drawer.closeDrawer(GravityCompat.START);
}
private void setupDrawerContent (NavigationView navigationView) {
navigationView.setNavigationItemSelectedListener (new NavigationView.OnNavigationItemSelectedListener() {
#Override
public boolean onNavigationItemSelected(#NonNull MenuItem item) {
selectItemDrawer(item);
return true;
}
});
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.listmenu,menu);
Drawable icon =menu.getItem(0).getIcon();
icon.mutate();
icon.setColorFilter(getResources().getColor(android.R.color.black), PorterDuff.Mode.SRC_IN);
return super.onCreateOptionsMenu(menu);
}
public void deleteTask(View view){
View parent = (View)view.getParent();
TextView taskTextView = (TextView)findViewById(R.id.task_title);
String task = String.valueOf(taskTextView.getText());
dbHelper.deleteTask(task);
loadTaskList();
}
}
If you don't want navigation to close with each click, write like this :
NavigationView navigationView = findViewById(R.id.navigationView);
navigationView.bringToFront();
you can use it after switch
switch(id){
}
//Set menuItem checked and title
menuItem.setChecked(true);
// close drawer when item is tapped
mDrawerLayout.closeDrawers();
return false;
its obvious in Default drawerlayout on your click it has to be close,if you wana get command on your drawerlayot , hen you have to use custom drawerlayout, or you can add the library, don't forget to import the library manually not in your gradle, then you can edit the library, and chose the functions .
try this Library
I want to Implement Onclick Item in recyclerView To open new activity I can pass data from one to another activity but in the code cannot figure out where to Implement on click onclicklistener if anyone is free to help me edit and give intent to Details.class
as I am getting data from firebase its first time to work on firebase any help would be appreciated.
import android.content.ActivityNotFoundException;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
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.RecyclerView;
import android.support.v7.widget.StaggeredGridLayoutManager;
import android.support.v7.widget.Toolbar;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.ScaleAnimation;
import android.widget.ImageView;
import android.widget.TextView;
import com.dekhou.provissionstore.model.Movie;
import com.firebase.ui.database.FirebaseRecyclerAdapter;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;
import com.squareup.picasso.Picasso;
public class MainActivity extends AppCompatActivity
implements NavigationView.OnNavigationItemSelectedListener {
private FloatingActionButton fab;
ScaleAnimation shrinkAnim;
private RecyclerView mRecyclerView;
private StaggeredGridLayoutManager mLayoutManager;
private TextView tvNoMovies,tvNoMovies1;
private Context context;
//Getting reference to Firebase Database
FirebaseDatabase database = FirebaseDatabase.getInstance();
DatabaseReference mDatabaseReference = database.getReference();
private static final String userId = "01";
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
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);
//Initializing our Recyclerview
mRecyclerView = (RecyclerView) findViewById(R.id.my_recycler_view);
tvNoMovies = (TextView) findViewById(R.id.tv_no_movies);
//tvNoMovies1 = (TextView) findViewById(R.id.addresstxt);
//scale animation to shrink floating actionbar
shrinkAnim = new ScaleAnimation(1.15f, 0f, 1.15f, 0f, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
if (mRecyclerView != null) {
//to enable optimization of recyclerview
mRecyclerView.setHasFixedSize(true);
}
//using staggered grid pattern in recyclerview
mLayoutManager = new StaggeredGridLayoutManager(1, StaggeredGridLayoutManager.VERTICAL);
mRecyclerView.setLayoutManager(mLayoutManager);
//Say Hello to our new FirebaseUI android Element, i.e., FirebaseRecyclerAdapter
FirebaseRecyclerAdapter<Movie,MovieViewHolder> adapter = new FirebaseRecyclerAdapter<Movie, MovieViewHolder>(
Movie.class,
R.layout.movie_board_item,
MovieViewHolder.class,
//referencing the node where we want the database to store the data from our Object
mDatabaseReference.child("users").child(userId).child("shops").getRef()
) {
#Override
protected void populateViewHolder(MovieViewHolder viewHolder, final Movie model, final int position) {
if(tvNoMovies.getVisibility()== View.VISIBLE){
tvNoMovies.setVisibility(View.GONE);
}
viewHolder.tvMovieName.setText(model.getMovieName());
viewHolder.address.setText(model.getAddress());
viewHolder.phone.setText(model.getPhone());
viewHolder.lit.setText(model.getLit());
viewHolder.lon.setText(model.getLon());
Picasso.with(MainActivity.this).load(model.getMoviePoster()).into(viewHolder.ivMoviePoster);
// all your stuff
}
};
mRecyclerView.setAdapter(adapter);
fab = (FloatingActionButton) findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
getSupportFragmentManager().beginTransaction()
.replace(R.id.frame_container, new AddMovieFragment())
.addToBackStack(null)
.commit();
//animation being used to make floating actionbar disappear
shrinkAnim.setDuration(400);
fab.setAnimation(shrinkAnim);
shrinkAnim.start();
shrinkAnim.setAnimationListener(new Animation.AnimationListener() {
#Override
public void onAnimationStart(Animation animation) {
}
#Override
public void onAnimationEnd(Animation animation) {
//changing floating actionbar visibility to gone on animation end
fab.setVisibility(View.GONE);
}
#Override
public void onAnimationRepeat(Animation animation) {
}
});
}
});
}
#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) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.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();
//noinspection SimplifiableIfStatement
if (id == R.id.menu_map) {
Intent intent = new Intent(this, MapsActivity.class);
this.startActivity(intent);
}
return super.onOptionsItemSelected(item);
}
#SuppressWarnings("StatementWithEmptyBody")
#Override
public boolean onNavigationItemSelected(MenuItem item) {
// Handle navigation view item clicks here.
int id = item.getItemId();
if (id == R.id.nav_slideshow) {
Intent cinemaIntent = new Intent(this, MapsActivity.class);
startActivity(cinemaIntent);
} else if (id == R.id.nav_manage) {
Intent cinemaIntent = new Intent(this, Get_Data.class);
startActivity(cinemaIntent);
} else if (id == R.id.nav_share) {
try {
//try to open page in facebook native app.
String uri = "fb://page/" + "293069792077"; //Cutsom URL
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(uri));
startActivity(intent);
}catch (ActivityNotFoundException ex){
//facebook native app isn't available, use browser.
String uri = "http://touch.facebook.com/pages/x/" + "293069792077"; //Normal URL
Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse(uri));
startActivity(i);
}
} else if (id == R.id.nav_send) {
Intent cinemaIntent = new Intent(this, About_Us.class);
startActivity(cinemaIntent);
}
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
drawer.closeDrawer(GravityCompat.START);
return true;
}
//ViewHolder for our Firebase UI
public static class MovieViewHolder extends RecyclerView.ViewHolder{
TextView tvMovieName,address,phone,lit,lon;
ImageView ivMoviePoster;
public MovieViewHolder(View v) {
super(v);
tvMovieName = (TextView) v.findViewById(R.id.tv_name);
address = (TextView) v.findViewById(R.id.address1);
phone = (TextView) v.findViewById(R.id.tv_phone);
lit = (TextView) v.findViewById(R.id.geo);
lon = (TextView) v.findViewById(R.id.geo2);
ivMoviePoster = (ImageView) v.findViewById(R.id.iv_movie_poster);
}
}
}
Add onClickListener to the itemView for your ViewHolder in populateViewHolder and start the Activity. like the below example.
#Override
protected void populateViewHolder(MovieViewHolder viewHolder, final Movie model, final int position) {
if(tvNoMovies.getVisibility()== View.VISIBLE){
tvNoMovies.setVisibility(View.GONE);
}
viewHolder.tvMovieName.setText(model.getMovieName());
viewHolder.address.setText(model.getAddress());
viewHolder.phone.setText(model.getPhone());
viewHolder.lit.setText(model.getLit());
viewHolder.lon.setText(model.getLon());
Picasso.with(MainActivity.this).load(model.getMoviePoster()).into(viewHolder.ivMoviePoster);
viewHolder.itemView.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent intent = new Intent(MainActivity.this, DetailActivity.class);
//intent.putExtra("model", model);
intent.putExtra("latitude", model.getLit());
intent.putExtra("longitude", model.getLon());
startActivity(intent);
}
});
// all your stuff
}
try this add onClickListener in your populateViewHolderlike this
#Override
protected void populateViewHolder(MovieViewHolder viewHolder, final Movie model, final int position) {
if(tvNoMovies.getVisibility()== View.VISIBLE){
tvNoMovies.setVisibility(View.GONE);
}
viewHolder.tvMovieName.setText(model.getMovieName());
viewHolder.address.setText(model.getAddress());
viewHolder.phone.setText(model.getPhone());
viewHolder.lit.setText(model.getLit());
viewHolder.lon.setText(model.getLon());
Picasso.with(MainActivity.this).load(model.getMoviePoster()).into(viewHolder.ivMoviePoster);
viewHolder.tvMovieName.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent intent = new Intent(MainActivity.this, DetailActivity.class);
startActivity(intent);
}
});
}
I have a application but i want use now interstitial banner.
Now it uses only the small banner.
I need to use an interstitial banner when the user opens my application.
But I cannot use with it in my app.
My question is; how to put an interstitial banner when the user opens my application?
I don't know how to push it.
This is my main activity
import android.content.Context;
import android.content.Intent;
import com.google.android.gms.ads.AdListener;
import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.InterstitialAd;
import android.content.res.Configuration;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.view.GravityCompat;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.ActionBar;
import android.support.v7.app.ActionBarActivity;
import android.support.v7.app.ActionBarDrawerToggle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.Toolbar;
import android.view.MenuItem;
import android.view.View;
import com.google.android.gms.analytics.GoogleAnalytics;
import com.mycompany.krakowiewdk.CityGuideApplication;
import com.mycompany.krakowiewdk.R;
import com.mycompany.krakowiewdk.adapter.DrawerAdapter;
import com.mycompany.krakowiewdk.database.dao.CategoryDAO;
import com.mycompany.krakowiewdk.database.model.CategoryModel;
import com.mycompany.krakowiewdk.fragment.PoiListFragment;
import com.mycompany.krakowiewdk.listener.OnSearchListener;
import com.mycompany.krakowiewdk.utility.ResourcesHelper;
import com.mycompany.krakowiewdk.view.DrawerDividerItemDecoration;
import com.mycompany.krakowiewdk.view.ScrimInsetsFrameLayout;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
public class MainActivity extends ActionBarActivity implements DrawerAdapter.CategoryViewHolder.OnItemClickListener, OnSearchListener {
private DrawerLayout mDrawerLayout;
private ActionBarDrawerToggle mDrawerToggle;
private ScrimInsetsFrameLayout mDrawerScrimInsetsFrameLayout;
private DrawerAdapter mDrawerAdapter;
private static final String ADMOB_INTERSTITIAL_UNIT_ID = "ca-app-pub-9431671174707107/7681038866";
private InterstitialAd mInterstitialAd;
private CharSequence mTitle;
private CharSequence mDrawerTitle;
private List<CategoryModel> mCategoryList;
public static Intent newIntent(Context context) {
Intent intent = new Intent(context, MainActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
return intent;
}
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
setupActionBar();
setupRecyclerView();
setupDrawer(savedInstanceState);
// init analytics tracker
((CityGuideApplication) getApplication()).getTracker();
}
#Override
public void onStart() {
super.onStart();
// analytics
GoogleAnalytics.getInstance(this).reportActivityStart(this);
}
#Override
public void onResume() {
super.onResume();
}
#Override
public void onPause() {
super.onPause();
}
#Override
public void onStop() {
super.onStop();
// analytics
GoogleAnalytics.getInstance(this).reportActivityStop(this);
}
#Override
public void onDestroy() {
super.onDestroy();
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// open or close the drawer if home button is pressed
if (mDrawerToggle.onOptionsItemSelected(item)) {
return true;
}
// action bar menu behaviour
switch (item.getItemId()) {
default:
return super.onOptionsItemSelected(item);
}
}
#Override
protected void onPostCreate(Bundle savedInstanceState) {
super.onPostCreate(savedInstanceState);
mDrawerToggle.syncState();
}
#Override
public void onConfigurationChanged(Configuration newConfiguration) {
super.onConfigurationChanged(newConfiguration);
mDrawerToggle.onConfigurationChanged(newConfiguration);
}
#Override
public void setTitle(CharSequence title) {
mTitle = title;
getSupportActionBar().setTitle(mTitle);
}
#Override
public void onItemClick(View view, int position, long id, int viewType) {
// position
int categoryPosition = mDrawerAdapter.getCategoryPosition(position);
selectDrawerItem(categoryPosition);
}
#Override
public void onSearch(String query) {
Fragment fragment = PoiListFragment.newInstance(query);
FragmentManager fragmentManager = getSupportFragmentManager();
fragmentManager.beginTransaction().replace(R.id.activity_main_container, fragment).commitAllowingStateLoss();
mDrawerAdapter.setSelected(mDrawerAdapter.getRecyclerPositionByCategory(0));
setTitle(getString(R.string.title_search) + ": " + query);
}
private void setupActionBar() {
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
ActionBar bar = getSupportActionBar();
bar.setDisplayUseLogoEnabled(false);
bar.setDisplayShowTitleEnabled(true);
bar.setDisplayShowHomeEnabled(true);
bar.setDisplayHomeAsUpEnabled(true);
bar.setHomeButtonEnabled(true);
}
private void setupRecyclerView() {
// reference
RecyclerView recyclerView = getRecyclerView();
// set layout manager
LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this);
linearLayoutManager.setOrientation(LinearLayoutManager.VERTICAL);
recyclerView.setLayoutManager(linearLayoutManager);
// load categories from database
loadCategoryList();
// set adapter
if (recyclerView.getAdapter() == null) {
// create adapter
mDrawerAdapter = new DrawerAdapter(mCategoryList, this);
} else {
// refill adapter
mDrawerAdapter.refill(mCategoryList, this);
}
recyclerView.setAdapter(mDrawerAdapter);
// add decoration
List<Integer> dividerPositions = new ArrayList<>();
dividerPositions.add(3);
RecyclerView.ItemDecoration itemDecoration = new DrawerDividerItemDecoration(
this,
null,
dividerPositions,
getResources().getDimensionPixelSize(R.dimen.global_spacing_xxs));
recyclerView.addItemDecoration(itemDecoration);
}
private void setupDrawer(Bundle savedInstanceState) {
mTitle = getTitle();
mDrawerTitle = getTitle();
// reference
mDrawerLayout = (DrawerLayout) findViewById(R.id.activity_main_layout);
mDrawerScrimInsetsFrameLayout = (ScrimInsetsFrameLayout) findViewById(R.id.activity_main_drawer);
// set drawer
mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START);
mDrawerLayout.setStatusBarBackgroundColor(ResourcesHelper.getValueOfAttribute(this, R.attr.colorPrimaryDark));
mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout, R.string.drawer_open, R.string.drawer_close) {
#Override
public void onDrawerClosed(View view) {
getSupportActionBar().setTitle(mTitle);
supportInvalidateOptionsMenu();
}
#Override
public void onDrawerOpened(View drawerView) {
getSupportActionBar().setTitle(mTitle);
supportInvalidateOptionsMenu();
}
};
mDrawerLayout.setDrawerListener(mDrawerToggle);
// show initial fragment
if (savedInstanceState == null) {
selectDrawerItem(0);
}
}
private void selectDrawerItem(int position) {
Fragment fragment = PoiListFragment.newInstance(mCategoryList.get(position).getId());
FragmentManager fragmentManager = getSupportFragmentManager();
fragmentManager.beginTransaction().replace(R.id.activity_main_container, fragment).commitAllowingStateLoss();
mDrawerAdapter.setSelected(mDrawerAdapter.getRecyclerPositionByCategory(position));
setTitle(mCategoryList.get(position).getName());
mDrawerLayout.closeDrawer(mDrawerScrimInsetsFrameLayout);
}
private void loadCategoryList() {
try {
mCategoryList = CategoryDAO.readAll(-1l, -1l);
} catch (SQLException e) {
e.printStackTrace();
}
CategoryModel all = new CategoryModel();
all.setId(PoiListFragment.CATEGORY_ID_ALL);
all.setName(getResources().getString(R.string.drawer_category_all));
all.setImage("drawable://" + R.drawable.ic_category_all);
CategoryModel favorites = new CategoryModel();
favorites.setId(PoiListFragment.CATEGORY_ID_FAVORITES);
favorites.setName(getResources().getString(R.string.drawer_category_favorites));
favorites.setImage("drawable://" + R.drawable.ic_category_favorites);
mCategoryList.add(0, all);
mCategoryList.add(1, favorites);
}
private RecyclerView getRecyclerView() {
return (RecyclerView) findViewById(R.id.activity_main_drawer_recycler);
}
}
Issue is resolved, i put code in mainactivity and show fine.
Context:
I am new to android. I have created a navigation drawer with fragments. When I run my code the app works but the choreographer says:
** frames skipped, heavy work is done in main thread.
The Problem:
The App became slow when I move to a fragment layout where there is more data. I searched for how to solve this problem and I learned using threads will solve the issue but I am so confused to use it.
Can anyone help me?
The Code:
package com.example.venkatesh.settaiboyz;
import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.ActionBar;
import android.support.v7.app.ActionBarActivity;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageButton;
public class MainActivity extends ActionBarActivity
implements NavigationDrawerFragment.NavigationDrawerCallbacks {
/**
* Fragment managing the behaviors, interactions and presentation of the navigation drawer.
*/
private NavigationDrawerFragment mNavigationDrawerFragment;
/**
* Used to store the last screen title. For use in {#link #restoreActionBar()}.
*/
private CharSequence mTitle;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mNavigationDrawerFragment = (NavigationDrawerFragment)
getSupportFragmentManager().findFragmentById(R.id.navigation_drawer);
mTitle = getTitle();
// Set up the drawer.
mNavigationDrawerFragment.setUp(
R.id.navigation_drawer,
(DrawerLayout) findViewById(R.id.drawer_layout));
}
#Override
public final void onNavigationDrawerItemSelected(int position) {
// update the main content by replacing fragments
Fragment fragment = null;
switch (position) {
case 0:
fragment = home_fragment.newInstance(position + 1);
break;
case 1:
fragment = member_fragment.newInstance(position + 1);
break;
case 2:
fragment = photo_fragment.newInstance(position + 1);
break;
case 3:
fragment = event_fragment.newInstance(position + 1);
break;
case 4:
fragment = about_fragment.newInstance(position + 1);
break;
}
FragmentManager fragmentManager = getSupportFragmentManager();
fragmentManager.beginTransaction()
.replace(R.id.container, fragment)
.commit();
}
public void onSectionAttached(int number) {
switch (number) {
case 1:
mTitle = getString(R.string.title_section1);
break;
case 2:
mTitle = getString(R.string.title_section2);
break;
case 3:
mTitle = getString(R.string.title_section3);
break;
case 4:
mTitle = getString(R.string.title_section4);
break;
case 5:
mTitle = getString(R.string.title_section5);
break;
}
}
public void restoreActionBar() {
ActionBar actionBar = getSupportActionBar();
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD);
actionBar.setDisplayShowTitleEnabled(true);
actionBar.setTitle(mTitle);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
if (!mNavigationDrawerFragment.isDrawerOpen()) {
// Only show items in the action bar relevant to this screen
// if the drawer is not showing. Otherwise, let the drawer
// decide what to show in the action bar.
getMenuInflater().inflate(R.menu.main, menu);
restoreActionBar();
return true;
}
return super.onCreateOptionsMenu(menu);
}
public static class PlaceholderFragment extends Fragment {
/**
* The fragment argument representing the section number for this
* fragment.
*/
private static final String ARG_SECTION_NUMBER = "section_number";
/**
* Returns a new instance of this fragment for the given section
* number.
*/
public static Fragment newInstance(int sectionNumber) {
PlaceholderFragment fragment = new PlaceholderFragment();
Bundle args = new Bundle();
args.putInt(ARG_SECTION_NUMBER, sectionNumber);
fragment.setArguments(args);
return fragment;
}
public PlaceholderFragment() {
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.home_layout, container, false);
return rootView;
}
#Override
public void onAttach(Activity activity) {
super.onAttach(activity);
((MainActivity) activity).onSectionAttached(
getArguments().getInt(ARG_SECTION_NUMBER));
}
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
switch (item.getItemId()) {
case R.id.action_facebook:
Open_facebook();
return true;
case R.id.action_twitter:
Open_Twitter();
return true;
default:
return super.onOptionsItemSelected(item);
}
}
//Anvar
public void OpenActivityAnvar(View view) {
setContentView(R.layout.anvar);
ImageButton b;
b = (ImageButton) findViewById(R.id.call_anvar);
b.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent callIntent = new Intent(Intent.ACTION_CALL);
callIntent.setData(Uri.parse("tel:+919841463562"));
startActivity(callIntent);
}
});
b = (ImageButton) findViewById(R.id.sms_anvar);
b.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent smsIntent = new Intent(Intent.ACTION_VIEW);
smsIntent.setType("vnd.android-dir/mms-sms");
smsIntent.putExtra("address", "+919841463562");
smsIntent.putExtra("sms_body", "");
startActivity(smsIntent);
}
});
b = (ImageButton) findViewById(R.id.mail_anvar);
b.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent intent = new Intent(Intent.ACTION_SEND);//common intent
intent.setData(Uri.parse("mailto:mailtoanvar8055#gmail.com"));
startActivity(intent);
}
});
}
//Main menu list
public void Open_facebook() {
Uri webpage = Uri.parse("https://www.facebook.com/settaiboyz");
Intent webIntent = new Intent(Intent.ACTION_VIEW, webpage);
startActivity(webIntent);
}
public void Open_Twitter() {
Uri webpage = Uri.parse("https://www.Twitter.com");
Intent webIntent = new Intent(Intent.ACTION_VIEW, webpage);
startActivity(webIntent);
}
}