0

ラジオボタンがほとんどないメインアクティビティがあります。config という名前の 1 つのボタンです。私がやりたいことは、構成をクリックすると新しいアクティビティが開始され、選択したラジオボタンのテキストが表示されることです。しかし、設定をクリックすると、アプリケーションが強制的に閉じられます。バグを特定できません。インテントについて学ぶために、次のリンクをたどりました 1) http://www.androidaspect.com/2012/07/passing-data-using-intent-object.html 2) http://www.androidaspect.com/2012 /02/how-to-start-new-activity-using-intent.html メイン アクティビティからの onclick のコードは次のとおりです。

configbtn.setOnClickListener(new Button.OnClickListener(){
        @Override
        public void onClick(View arg0) {            
            //Toast.makeText(getApplicationContext(), "You have clicked on 'Config'...", Toast.LENGTH_LONG).show();
            if(!mode.equals(""))
            {
            Intent i = new Intent("com.av.android.profiles.configActivity");
            Bundle myBundle = new Bundle();
            myBundle.putString("promode",mode);
            i.putExtras(myBundle);
            startActivityForResult(i, 1);
            }
             else
             {
                Toast.makeText(getApplicationContext(), "Please select profile mode to config...!", Toast.LENGTH_LONG).show();
             }

         }});

2 番目のアクティビティのコード:

public class configActivity extends Activity{


Bundle myBundle1 = new Bundle();
@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setContentView(R.layout.config);
    String myName = null;       
    Bundle extras = getIntent().getExtras();
    if(extras != null)
    {
        myName = extras.getString("promode");
    }


    TextView tvData = (TextView) findViewById(R.id.tvData);
    tvData.setText(myName);
    }}

前もって感謝します

4

2 に答える 2

1

使用する

if(extras != null)
    {
        myName = extras.getString("promode");
    }

それ以外の

if(extras != null)
    {
        myName = extras.getString("Name");
    }

promodeあなたはキーとして渡していないのでName

于 2012-08-25T12:29:09.897 に答える
0

試す

Intent i = new Intent(CurrentActvity.this,configActivity.class);
Bundle myBundle = new Bundle();
myBundle.putString("promode",mode);
i.putExtras(myBundle);
startActivityForResult(i, 1);

configActivityマニフェスト ファイルで宣言します。

<activity
            android:name=".configActivity" />

と使用myName = extras.getString("promode");

于 2012-08-25T12:29:16.127 に答える