gpt4 book ai didi

Android:将微调器选择传递给新 Activity

转载 作者:行者123 更新时间:2023-11-29 21:51:07 27 4
gpt4 key购买 nike

我正在开发一个项目,用户可以从微调器中选择最多五个选项,我想在按下提交按钮时在新 Activity 中显示所选选项我有一个新 Activity 在按下按钮时打开但没有显示,我需要有关我需要执行的步骤的帮助,这是我要显示数据的第二个屏幕的代码

    public class SecondScreenActivity extends Activity {

TextView FirstIwi;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.selected_iwi);





FirstIwi = (TextView) findViewById(R.id.spinner1);

Intent intename = getIntent();


String iwi1 = (String) intename.getSerializableExtra("USERNAME");
//Spinner spinnername2 = (Spinner) findViewById(R.id.spinner2);



FirstIwi.setText("First Iwi" + iwi1);


}
}

头等舱

    import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.Spinner;

public class IwiSelect extends Activity {

Spinner spinner1, spinner2, spinner3, spinner4, spinner5;
Button btnSubmit;
String iwi1;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_iwiselect);

addListenerOnButton();

}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.activity_iwi_select, menu);
return true;
}




// get the selected drop down list value
public void addListenerOnButton() {

spinner1 = (Spinner) findViewById(R.id.spinner1);
spinner2 = (Spinner) findViewById(R.id.spinner2);
spinner3 = (Spinner) findViewById(R.id.spinner3);
spinner4 = (Spinner) findViewById(R.id.spinner4);
spinner5 = (Spinner) findViewById(R.id.spinner5);

btnSubmit = (Button) findViewById(R.id.btnSubmit);

btnSubmit.setOnClickListener(new OnClickListener() {

public void onClick(View view) {

iwi1 = spinner1.toString();
//Starting a new Intent
Intent nextScreen = new Intent(IwiSelect.this, SecondScreenActivity.class);

//Sending data to another Activity
nextScreen.putExtra("USERNAME", iwi1);
//nextScreen.putExtra(spinner2.getContext().toString(), false);





// starting new activity
startActivity(nextScreen);




}
});

}
}

最佳答案

您需要使用以下代码:

// find spinner object here
Spinner spinner1 = (Spinner) findViewById(R.id.spinner1);
//get selected value here
String itemStr = spinnername1.getSelectedItem().toString();
//put selected vale and start new activity
Intent mIntent = new Intent(ActivityOne.this, NewActivity.class);
mIntent.putExtra("data", itemStr);
startActivity(mIntent);


/**
* AT receiver side activity in onCreate
*/
Intent i = getIntent();
String dataString = i.getString("data");

关于Android:将微调器选择传递给新 Activity ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14391967/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com