0

我在传递意图时在 imagebutton 处强制关闭。我没有传递意图,而是在 onclick 上传递了 toast,它已成功运行,但传递的意图未成功运行。

enter code here:

有什么可能???

package com.account;

import android.app.Activity;
import android.os.Bundle;
import android.content.Intent;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.*;
public class AccountTrackerActivity extends Activity implements OnClickListener{
    ImageButton user;
    ImageButton acc_list;
    ImageButton add_acc;
    ImageButton add_transaction;
    ImageButton search_trans;
    ImageButton remainder;
    ImageButton recent_trans;
    TextView curr_user;


    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        user=(ImageButton)findViewById(R.id.imageButton2);
        acc_list=(ImageButton)findViewById(R.id.imageButton3);
        add_acc=(ImageButton)findViewById(R.id.imageButton4);
        add_transaction=(ImageButton)findViewById(R.id.imageButton6);
        search_trans=(ImageButton)findViewById(R.id.imageButton7);
        remainder=(ImageButton)findViewById(R.id.imageButton8);
        recent_trans=(ImageButton)findViewById(R.id.imageButton5);
        curr_user= (TextView)findViewById(R.id.lblcurrent_user);

        user.setOnClickListener(this);
        acc_list.setOnClickListener(this);
        add_acc.setOnClickListener(this);
        add_transaction.setOnClickListener(this);
        search_trans.setOnClickListener(this);
        remainder.setOnClickListener(this);
        recent_trans.setOnClickListener(this);





    }
            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                try
                {

    if(v.getId()==user.getId()){                    

            Intent myIntentlogin=new Intent(AccountTrackerActivity.this,login.class);
            startActivityForResult(myIntentlogin,101);
            }
    if(v.getId()==acc_list.getId()){
        //Intent myIntentacc_list=new Intent(getApplicationContext(),acc_list.class);
        Toast.makeText(getApplicationContext(),"hi....", Toast.LENGTH_LONG).show();
        //startActivityForResult(myIntentacc_list,101);
        //startActivity(myIntentacc_list);
    }
    if(v.getId()==add_acc.getId()){
        Intent myIntentadd_acc=new Intent(AccountTrackerActivity.this,add_acc.class);
        startActivityForResult(myIntentadd_acc,103);

    }
    if(v.getId()==add_transaction.getId()){
        Intent myIntentadd_transaction=new Intent(AccountTrackerActivity.this,add_transaction.class);
        startActivityForResult(myIntentadd_transaction,104);
    }
    if(v.getId()==search_trans.getId()){
        Intent myIntentsearch_trans=new Intent(AccountTrackerActivity.this,search_trans.class);
        startActivityForResult(myIntentsearch_trans,105);
    }
    if(v.getId()==remainder.getId()){
        Intent myIntentremainder=new Intent(AccountTrackerActivity.this,remainder.class);
        startActivityForResult(myIntentremainder,106);
    }
    if(v.getId()==recent_trans.getId()){
        Intent myIntentrecent_trans=new Intent(AccountTrackerActivity.this,recent_trans.class);
        startActivityForResult(myIntentrecent_trans,107);
    }
                }
                catch(Exception e)
                {
                    Toast.makeText(getApplicationContext(), e.getMessage(), Toast.LENGTH_LONG).show();
                }


            }

}
4

2 回答 2

2

从一项活动中传递数据

 Intent myIntentlogin= new Intent(AccountTrackerActivity.this,login.class);
myIntentlogin.putExtra("message", 103); //pass data to new activity here like this
startActivity(myIntentlogin);

在另一个接收数据

Intent intent = getIntent();
String message = intent.getStringExtra("message");

参考这个链接

于 2013-04-06T06:21:05.313 回答
0

在你的代码中试试这个

       ImageButton ButtonOne=(ImageButton) findViewById(R.id.imageButton1);

下面给出了您的 onclick 侦听器

      ButtonOne.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View arg0) {
            // TODO Auto-generated method stub
            teamsName=db.getAllTeams();
            teamone=true;
            Intent intent=new    Intent(MainActivity.this,NextActivity.class);
            intent.putExtra("item", teamsName);
            startActivityForResult(intent, 0);
        }
    });

您需要在清单文件中添加您的 NextActivity。

您的 Mainfest 如下所示

      <application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity
        android:name="com.example.design.MainActivtiy"
        android:label="@string/app_name" 
         android:screenOrientation="portrait">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

   <activity
        android:name=".NextActivity"
        android:screenOrientation="portrait">
        </activity>
   </application>

  </manifest>
于 2013-04-06T06:07:52.843 回答