2016-07-01 11 views
-1

Ich habe ein paar Fehler in DrawerLayout und Google appindex API !! Ich bin mit diesem IntelliJ Android Studio :(Fehler in DrawerLayout und Appindex Google Play-API

hier ist DrawerLayout zu verrückt zu werden:

DL

hier Fehlermeldungen: EM

und hier ist mein HomaActivity (MainActivity) code:

package ir.homa; 

import android.net.Uri; 
import android.os.Bundle; 
import android.support.design.widget.FloatingActionButton; 
import android.support.design.widget.NavigationView; 
import android.support.design.widget.Snackbar; 
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.view.View; 
import java.util.HashMap; 
import ir.homa.SQLiteHandler; 
import ir.homa.SessionManager; 
import android.content.Intent; 
import android.widget.Button; 
import android.widget.TextView; 

import com.google.android.gms.appindexing.Action; 
import com.google.android.gms.appindexing.AppIndex; 
import com.google.android.gms.common.api.GoogleApiClient; 


public class HomaActivity extends AppCompatActivity 
     implements NavigationView.OnNavigationItemSelectedListener { 

    private TextView txtName; 
    private TextView txtEmail; 
    private Button btnLogout; 

    private SQLiteHandler db; 
    private SessionManager session; 
    /** 
    * ATTENTION: This was auto-generated to implement the App Indexing API. 
    * See https://g.co/AppIndexing/AndroidStudio for more information. 
    */ 
    private GoogleApiClient client; 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_homa); 
     Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); 
     setSupportActionBar(toolbar); 
     FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab); 
     fab.setOnClickListener(new View.OnClickListener() { 
      @Override 
      public void onClick(View view) { 
       Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG) 
         .setAction("Action", null).show(); 
      } 
     }); 
     txtName = (TextView) findViewById(R.id.name); 
     txtEmail = (TextView) findViewById(R.id.email); 


     // SqLite database handler 
     db = new SQLiteHandler(getApplicationContext()); 

     // session manager 
     session = new SessionManager(getApplicationContext()); 

     if (!session.isLoggedIn()) { 
      logoutUser(); 
     } 

     // Fetching user details from sqlite 
     HashMap<String, String> user = db.getUserDetails(); 

     String name = user.get("name"); 
     String email = user.get("email"); 

     // Displaying the user details on the screen 
     txtName.setText(name); 
     txtEmail.setText(email); 

     // Logout button click event 
     btnLogout.setOnClickListener(new View.OnClickListener() { 

      @Override 
      public void onClick(View v) { 
       logoutUser(); 
      } 
     }); 
     // ATTENTION: This was auto-generated to implement the App Indexing API. 
     // See https://g.co/AppIndexing/AndroidStudio for more information. 
     client = new GoogleApiClient.Builder(this).addApi(AppIndex.API).build(); 
    } 

    /** 
    * Logging out the user. Will set isLoggedIn flag to false in shared 
    * preferences Clears the user data from sqlite users table 
    */ 
    private void logoutUser() { 
     session.setLogin(false); 

     db.deleteUsers(); 

     // Launching the login activity 
     Intent intent = new Intent(HomaActivity.this, LoginActivity.class); 
     startActivity(intent); 
     finish(); 
    } 

    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) { 
     // Inflate the menu; this adds items to the action bar if it is present. 
     getMenuInflater().inflate(R.menu.homa, 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) { 
     // 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; 
    } 

    @Override 
    public void onStart() { 
     super.onStart(); 

     // ATTENTION: This was auto-generated to implement the App Indexing API. 
     // See https://g.co/AppIndexing/AndroidStudio for more information. 
     client.connect(); 
     Action viewAction = Action.newAction(
       Action.TYPE_VIEW, // TODO: choose an action type. 
       "Homa Page", // TODO: Define a title for the content shown. 
       // TODO: If you have web page content that matches this app activity's content, 
       // make sure this auto-generated web page URL is correct. 
       // Otherwise, set the URL to null. 
       Uri.parse("http://host/path"), 
       // TODO: Make sure this auto-generated app URL is correct. 
       Uri.parse("android-app://ir.homa/http/host/path") 
     ); 
     AppIndex.AppIndexApi.start(client, viewAction); 
    } 

    @Override 
    public void onStop() { 
     super.onStop(); 

     // ATTENTION: This was auto-generated to implement the App Indexing API. 
     // See https://g.co/AppIndexing/AndroidStudio for more information. 
     Action viewAction = Action.newAction(
       Action.TYPE_VIEW, // TODO: choose an action type. 
       "Homa Page", // TODO: Define a title for the content shown. 
       // TODO: If you have web page content that matches this app activity's content, 
       // make sure this auto-generated web page URL is correct. 
       // Otherwise, set the URL to null. 
       Uri.parse("http://host/path"), 
       // TODO: Make sure this auto-generated app URL is correct. 
       Uri.parse("android-app://ir.homa/http/host/path") 
     ); 
     AppIndex.AppIndexApi.end(client, viewAction); 
     client.disconnect(); 
    } 
} 

Ich habe einige e Schief über Google Play AppIndex mitten in diesen Fehlern! Hilfe ..!

Antwort

0
@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_homa); 
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); 
    setSupportActionBar(toolbar); 
    FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab); 
    fab.setOnClickListener(new View.OnClickListener() { 
     @Override 
     public void onClick(View view) { 
      Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG) 
        .setAction("Action", null).show(); 
     } 
    }); 
    txtName = (TextView) findViewById(R.id.name); 
    txtEmail = (TextView) findViewById(R.id.email); 


    // SqLite database handler 
    db = new SQLiteHandler(getApplicationContext()); 

    // session manager 
    session = new SessionManager(getApplicationContext()); 

    if (!session.isLoggedIn()) { 
     logoutUser(); 
    } 

    // Fetching user details from sqlite 
    HashMap<String, String> user = db.getUserDetails(); 

    String name = user.get("name"); 
    String email = user.get("email"); 

    // Displaying the user details on the screen 
    txtName.setText(name); 
    txtEmail.setText(email); 

    // Logout button click event 
    btnLogout.setOnClickListener(new View.OnClickListener() { 

     @Override 
     public void onClick(View v) { 
      logoutUser(); 
     } 
    }); 
    // ATTENTION: This was auto-generated to implement the App Indexing API. 
    // See https://g.co/AppIndexing/AndroidStudio for more information. 
    client = new GoogleApiClient.Builder(this).addApi(AppIndex.API).build(); 


    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); 
} 






/** 
* Logging out the user. Will set isLoggedIn flag to false in shared 
* preferences Clears the user data from sqlite users table 
*/ 
private void logoutUser() { 
    session.setLogin(false); 

    db.deleteUsers(); 

    // Launching the login activity 
    Intent intent = new Intent(HomaActivity.this, LoginActivity.class); 
    startActivity(intent); 
    finish(); 
} 
+0

Ich habe es unter onCreate bruckets – Mohammadreza

+0

den Code setzen in Bezug auf drawerlayout und navigationview innerhalb onCreate geschweiften Klammern – ebyt

Verwandte Themen