如何将微调器中的数据提取到另一个布局?
How can I extract data from spinners to another layout?
我的申请需要帮助。我在一个布局中放置了一些微调器,我需要检索 SelectedItems 中的文本以将它们放置在另一个布局中,也许在 TextView 中。
我用过:
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
String selecTipoCP = parent.getItemAtPosition(position).toString();
String TipoCP = selecTipoCP;
Intent intent1 = new Intent(CPOrder.this,Finalizar.class);
intent1.putExtra("var_tipoCP", TipoCP);
startActivity(intent1);
}
它运行正常,但 activity 立即启动。我想进入这个布局,我想在按下按钮时才启动activity。
您只需要分离您的代码即可添加您想要的功能。
为您的按钮创建一个事件。
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position,long id) {
addCustomListenerOnSpinner();
}
private void addCustomListenerOnSpinner(){
yourButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
String value=String.valueOf(yourSpinner.getSelectedItem());
Intent intent1 = new Intent(CPOrder.this,Finalizar.class);
intent1.putExtra("var_tipoCP", value);
startActivity(intent1);
}
});
}
其他方式...
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position,long id) {
//only we pass the data
addCustomListenerOnSpinner(parent,position);
}
private void addCustomListenerOnSpinner(final AdapterView<?> parent,final int position){
yourButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
String selecTipoCP =parent.getItemAtPosition(position).toString();
Intent intent1 = new Intent(CPOrder.this,Finalizar.class);
intent1.putExtra("var_tipoCP", selecTipoCP);
startActivity(intent1);
}
});
}
我的申请需要帮助。我在一个布局中放置了一些微调器,我需要检索 SelectedItems 中的文本以将它们放置在另一个布局中,也许在 TextView 中。
我用过:
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
String selecTipoCP = parent.getItemAtPosition(position).toString();
String TipoCP = selecTipoCP;
Intent intent1 = new Intent(CPOrder.this,Finalizar.class);
intent1.putExtra("var_tipoCP", TipoCP);
startActivity(intent1);
}
它运行正常,但 activity 立即启动。我想进入这个布局,我想在按下按钮时才启动activity。
您只需要分离您的代码即可添加您想要的功能。
为您的按钮创建一个事件。
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position,long id) {
addCustomListenerOnSpinner();
}
private void addCustomListenerOnSpinner(){
yourButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
String value=String.valueOf(yourSpinner.getSelectedItem());
Intent intent1 = new Intent(CPOrder.this,Finalizar.class);
intent1.putExtra("var_tipoCP", value);
startActivity(intent1);
}
});
}
其他方式...
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position,long id) {
//only we pass the data
addCustomListenerOnSpinner(parent,position);
}
private void addCustomListenerOnSpinner(final AdapterView<?> parent,final int position){
yourButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
String selecTipoCP =parent.getItemAtPosition(position).toString();
Intent intent1 = new Intent(CPOrder.this,Finalizar.class);
intent1.putExtra("var_tipoCP", selecTipoCP);
startActivity(intent1);
}
});
}