簡體   English   中英

eclipse android中的意圖問題

[英]Intents issue in eclipse android

我有意圖的問題。 我在主要活動中使用它並調用另一個活動,但單擊它再次調用主要活動。 這是我的代碼

主要活動.java

package com.umair.facebook; 

import android.app.Activity; 
import android.content.Intent; 
import android.os.Bundle; 
import android.view.View; 
import android.widget.Button; 
import android.widget.EditText; 
import android.widget.ImageView; 
import android.widget.TextView; 

public class MainActivity extends Activity { 

    ImageView img1; 
    TextView txt, txt3; 
    Button like, share, update; 
    EditText et1; 

    @Override 
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState); 

        setContentView(R.layout.activity_main); 

        img1 = (ImageView) findViewById(R.id.img); 
        txt = (TextView) findViewById(R.id.name); 
        txt3 = (TextView) findViewById(R.id.status); 
        like = (Button) findViewById(R.id.Like); 
        share = (Button) findViewById(R.id.Share); 
        update = (Button) findViewById(R.id.Comment); 
        et1 = (EditText) findViewById(R.id.editText1); 

        like.setOnClickListener(new View.OnClickListener() { 
            @Override public void onClick(View v) { 
                // TODO Auto-generated method stub 
                like.setText("Liked"); 
             } 
         }); 

         share.setOnClickListener(new View.OnClickListener() { 
             @Override 
             public void onClick(View v) { 
                 // TODO Auto-generated method stub 
                 share.setText("Shared"); 
             } 
         }); 

         update.setOnClickListener(new View.OnClickListener() { 
             @Override 
             public void onClick(View v) { 
                 // TODO Auto-generated method stub startGame(); 
             } 
         }); 
     } 

     private void startGame() { 
         // TODO Auto-generated method stub 
         Intent lanuchGame = new Intent(MainActivity.this, Result.class); 
         startActivity(lanuchGame); 
      } 
 } 

Result.java(第二個活動)

 package com.umair.facebook; 
 import android.os.Bundle; 
 import android.widget.Button; 
 import android.widget.EditText; 
 import android.widget.ImageView; 
 import android.widget.TextView; 

 public class Result extends MainActivity { 

     ImageView img; 
     TextView txt1, txt2;
     Button btn1, btn2,btn3; 
     EditText et; 

     @Override 
     protected void onCreate(Bundle savedInstanceState) { 
         // TODO Auto-generated method stub
         setContentView(R.layout.result_1); 
         super.onCreate(savedInstanceState); 

         img =(ImageView)findViewById(R.id.img1); 
         txt1= (TextView)findViewById(R.id.nam); 
         txt2= (TextView)findViewById(R.id.stats); 
         btn1=(Button)findViewById(R.id.Liked); 
         btn2=(Button)findViewById(R.id.Shared); 
         et=(EditText)findViewById(R.id.editText); } }

在第二個Activity setContentView() super.onCreate(savedInstanceState)之前調用super.onCreate(savedInstanceState)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM