zoukankan      html  css  js  c++  java
  • Androdi 开发学习四 Activity和Intent

    1:视频

    http://edu.51cto.com/lesson/id-15687.html

    马老师的  android视频教程第五节

    2:遇到问题

    The method setOnClickListener(View.OnClickListener) in the type View is not

    解决方法:

    http://www.cnblogs.com/yigerendehaibian/archive/2012/12/08/2809141.html

    http://bbs.51cto.com/thread-1024351-1.html

    3:注意第4行和第8行只能存在一个,否则会造成冲突

    MainActivity.java

     1 package com.helloworld1;
     2 
     3 import android.app.Activity;
     4 import android.content.Intent;
     5 import android.support.v7.app.ActionBarActivity;
     6 //import android.content.DialogInterface.OnClickListener;
     7 import android.os.Bundle;
     8 import android.view.Menu;
     9 import android.view.View;
    10 import android.view.View.OnClickListener;
    11 import android.view.MenuItem;
    12 import android.widget.Button;
    13 import android.widget.TextView;
    14 import android.content.DialogInterface;
    15 
    16 
    17 public class MainActivity extends ActionBarActivity {
    18 
    19     @Override
    20     protected void onCreate(Bundle savedInstanceState) {
    21         super.onCreate(savedInstanceState);
    22         setContentView(R.layout.activity_main);
    23         TextView myTextView = (TextView)findViewById(R.id.MyTextView);
    24         Button myButtonView = (Button)findViewById(R.id.MyButtonView);
    25         myTextView.setText("我的第一个Text View");
    26         myButtonView.setText("我的第一个Button View" + "
    " + "guolong");
    27         findViewById(R.id.MyButtonView).setOnClickListener(new MybuttonListener());  
    28 
    29     }
    30 
    31     class MybuttonListener implements OnClickListener
    32     {
    33         public void onClick(View v) {  
    34             Intent intent = new Intent(MainActivity.this, OtherActivity.class);  
    35             intent.putExtra("data", "mainActivity");  
    36             startActivity(intent);    
    37      
    38         }
    39     }
    View Code

    OtherActivity.java

     1 package com.helloworld1;
     2 
     3 
     4 import android.support.v7.app.ActionBarActivity;
     5 import android.content.Intent;
     6 import android.os.Bundle;
     7 import android.view.Menu;
     8 import android.view.MenuItem;
     9 import android.widget.Button;
    10 import android.widget.TextView;
    11 
    12 public class OtherActivity extends ActionBarActivity{
    13     private TextView myTextView = null;
    14     @Override
    15     protected void onCreate(Bundle savedInstanceState) {
    16         // TODO Auto-generated method stub
    17         super.onCreate(savedInstanceState);
    18         setContentView(R.layout.other_main);
    19         Intent intent = getIntent();
    20         String value = intent.getStringExtra("data");
    21         myTextView = (TextView)findViewById(R.id.MyTextView);
    22         myTextView.setText(value);
    23     }
    24 }
    View Code
  • 相关阅读:
    2016-02-24 工作日记
    金字塔培训
    你找到自己的路了么?
    你是个成熟的职场人么?
    码农十年总结
    码农十年连载六
    码农十年连载五
    码农十年连载四
    码农十年连载三
    码农十年连载二
  • 原文地址:https://www.cnblogs.com/xiaoxiong0222/p/4349153.html
Copyright © 2011-2022 走看看