在我的应用程序中,我使用的是抽屉布局,这是您在创建新活动时可以使用的默认布局。
然而,它不顺畅,它有一个相当大的滞后/打破开/关菜单,我在这里包括我的MainActivity.java。我四处搜寻但没找到任何东西。
这是我的抽屉布局:
可以修复吗?
package com.example.bugdroid.menuexe.Activities;
import android.content.Intent;
import android.database.Cursor;
import android.database.DatabaseUtils;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.os.Environment;
import android.os.Handler;
import android.provider.CalendarContract;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
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.Button;
import android.widget.ImageButton;
import android.widget.TextView;
import android.widget.Toast;
import com.example.bugdroid.menuexe.R;
import com.example.bugdroid.menuexe.database.DAL;
import com.example.bugdroid.menuexe.database.DBAccessMode;
import com.example.bugdroid.menuexe.database.DBContract;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
public class MainActivity extends AppCompatActivity
implements NavigationView.OnNavigationItemSelectedListener {
private DAL dal;
private TextView Nsintomas;
private ImageButton Adicionar;
private ImageButton VerRegistos;
private ImageButton Calendario;
private ImageButton Consultas;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
Nsintomas = (TextView) findViewById(R.id.Nsintomas);
Adicionar = (ImageButton) findViewById(R.id.addSintoma);
VerRegistos = (ImageButton) findViewById(R.id.btnVerRegistos);
Calendario = (ImageButton) findViewById(R.id.btnCalendario);
Consultas = (ImageButton) findViewById(R.id.btnConsultas);
// Pega na informação da tabela Reg_Sintomas
dal = new DAL(this);
dal.connect(DBAccessMode.READ);
long returnval = dal.getTaskCount();
Nsintomas.setText(String.valueOf(returnval));
/* Cursor res = dal.selectALLFromRegSintomas();
String regs = "";
res.moveToFirst();
while (!res.isAfterLast()) {
regs += res.getInt(res.getColumnIndex(DBContract.Reg_sintomas._ID));
regs += " - ";
regs += res.getString(res.getColumnIndex(DBContract.Reg_sintomas.COL_Sintoma));
regs += "\n";
regs += res.getString(res.getColumnIndex(DBContract.Reg_sintomas.COL_D_Inicio));
regs += "\n";
regs += res.getString(res.getColumnIndex(DBContract.Reg_sintomas.COL_H_Inicio));
regs += "\n";
regs += res.getString(res.getColumnIndex(DBContract.Reg_sintomas.COL_D_Fim));
regs += "\n";
regs += res.getString(res.getColumnIndex(DBContract.Reg_sintomas.COL_H_Fim));
regs += "\n";
regs += res.getString(res.getColumnIndex(DBContract.Reg_sintomas.COL_Intensidade));
regs += "\n";
res.moveToNext();
}*/
Cursor res2 = dal.VerMedicacao();
String xdxd = "";
res2.moveToFirst();
while (!res2.isAfterLast()) {
xdxd += res2.getString(res2.getColumnIndex(DBContract.Sintoma_medicacao.COL_ID_sintoma));
xdxd += "\n";
xdxd += res2.getString(res2.getColumnIndex(DBContract.Sintoma_medicacao.COL_ID_medicacao));
xdxd += "\n";
res2.moveToNext();
}
//dal.disconnect();
//TextView tv = (TextView) findViewById(R.id.teste);
//tv.setText(regs);
Adicionar.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Intent intent = new Intent(MainActivity.this, InsertFirstActivity.class);
startActivity(intent);
}
});
VerRegistos.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// String frase = "O orlando";
Intent intent = new Intent(MainActivity.this, VerRegsSintomas.class);
startActivity(intent);
}
});
Calendario.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Intent intent = new Intent(MainActivity.this, Calendario.class);
startActivity(intent);
}
});
Consultas.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Intent arroz = new Intent(MainActivity.this, VerConsultas.class);
startActivity(arroz);
}
});
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);
}
boolean doubleBackToExitPressedOnce = false;
@Override
public void onBackPressed() {
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
if (drawer.isDrawerOpen(GravityCompat.START)) {
drawer.closeDrawer(GravityCompat.START);
} else {
}
if (doubleBackToExitPressedOnce) {
super.onBackPressed();
return;
}
this.doubleBackToExitPressedOnce = true;
Toast.makeText(this, "Prima a tecla outra vez para sair", Toast.LENGTH_SHORT).show();
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
doubleBackToExitPressedOnce = false;
}
}, 2000);
}
@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.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
@SuppressWarnings("StatementWithEmptyBody")
@Override
public boolean onNavigationItemSelected(MenuItem item) {
int id = item.getItemId();
if (id == R.id.nav_export) {
} else if (id == R.id.nav_defs) {
Intent intent = new Intent(MainActivity.this, MyPreferenceActivity.class);
startActivity(intent);
} else if (id == R.id.nav_consultas) {
Intent intent = new Intent(Intent.ACTION_INSERT)
.setData(CalendarContract.Events.CONTENT_URI)
.putExtra(CalendarContract.Events.TITLE, "Nova Consulta")
.putExtra(CalendarContract.Events.DESCRIPTION, "Não esquecer de ir a esta consulta");
if (intent.resolveActivity(getPackageManager()) != null) {
startActivity(intent);
}
} else if (id == R.id.nav_feed) {
}
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
drawer.closeDrawer(GravityCompat.START);
return true;
}
}