android 登录代码,简单登录页面

这个博客展示了如何在Android应用中实现菜单的创建和选项点击事件的处理。在MainActivity中,通过onCreateOptionsMenu加载菜单,并在onOptionsItemSelected中处理用户对性别和兴趣爱好选项的点击,更新TextView的内容。
摘要由CSDN通过智能技术生成

[android]代码库package com.example.demo_menu20151002474;

import android.app.Activity;

import android.os.Bundle;

import android.view.Menu;

import android.view.MenuItem;

import android.widget.TextView;

public class MainActivity extends Activity {

TextView gender, hobby;

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

gender = (TextView) this.findViewById(R.id.gender);

hobby = (TextView) this.findViewById(R.id.hobby);

}

@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();

switch (item.getItemId()) {

case R.id.male:

case R.id.female:

item.setChecked(true);

gender.setText(item.getTitle());

break;

case R.id.sport:

case R.id.sing:

case R.id.trip:

item.setChecked(!item.isChecked());

if (item.isChecked())

hobby.setText(hobby.getText().toString() + item.getTitle());

break;

}

return super.onOptionsItemSelected(item);

}

}

[源代码打包下载]

694748ed64b9390909c0d88230893790.png

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值