当我将HomePage活动更改为从ListView扩展时,菜单项不再可见。

时间:2015-02-11 10:31:58

标签: android android-listview android-studio

在我的主页活动中,我的应用程序中有一个菜单,其中包含一个更新按钮,该按钮设置为"始终"可见,并且注销按钮设置为"从不"可见。目前主页活动从ActionBarActivity扩展,但是,当我更改活动,因此从listActivity扩展时,菜单不再存在。有解决方案吗?

activity_homepage.xml

<?xml version="1.0"?>
<RelativeLayout tools:context=".MainActivity" android:paddingBottom="@dimen/activity_vertical_margin" android:paddingTop="@dimen/activity_vertical_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:layout_height="match_parent"
android:layout_width="match_parent" xmlns:tools="http://schemas.android.com/tools" xmlns:android="http://schemas.android.com/apk/res/android">
 </RelativeLayout>




menu_homepage.xml

<?xml version="1.0"?>

-<menu tools:context=".MainActivity" xmlns:tools="http://schemas.android.com/tools" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:android="http://schemas.android.com/apk/res/android">

<item android:title="@string/action_settings" app:showAsAction="never" android:orderInCategory="100" android:id="@+id/action_settings"/>

<item android:title="Update" app:showAsAction="always" android:id="@+id/updateStatus"/>

<item android:title="Logout" app:showAsAction="never" android:id="@+id/LogoutUser"/>

</menu>





package com.exchange345.exchangeapp;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.view.Menu;
import android.view.MenuItem;

import com.parse.ParseUser;


public class HomePageActivity extends ActionBarActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {



        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_homepage);


        ParseUser currentUser = ParseUser.getCurrentUser();
        if (currentUser != null) {
            // show user the homepage


        } else {
            // TAKE USER TO LOGIN

            Intent takeUserToLogin = new Intent (this, LoginActivity.class);
            startActivity(takeUserToLogin);
        }

    }


    @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_homepage, 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
       switch(id){
           case R.id.updateStatus:
               //take user to update status activity
               Intent intent = new Intent(this, UpdateStatusActivity.class);
               startActivity(intent);

               break;

           case R.id.LogoutUser:
               //logout the user


               //user goes back to log in activity
               Intent takeUserToLogin = new Intent(this, LoginActivity.class);
               startActivity(takeUserToLogin);
               ParseUser.logOut();

               break;
       }

        return super.onOptionsItemSelected(item);
    }
}

0 个答案:

没有答案