Java 在下面的程序中,如何在类似微调器的textview中显示GetCountryZipCode()?

Java 在下面的程序中,如何在类似微调器的textview中显示GetCountryZipCode()?,java,android,Java,Android,我是Android新手。如何在微调器中显示GetCountryZipCode(),就像下面程序中的textview一样。我在textview中得到的输出与我希望在微调器中得到的输出相同,我如何在微调器中调用GetCountryCode()方法 public class MainActivity extends AppCompatActivity implements AdapterView.OnItemSelectedListener{ String [] rl; String

我是Android新手。如何在微调器中显示
GetCountryZipCode()
,就像下面程序中的
textview
一样。我在
textview
中得到的输出与我希望在微调器中得到的输出相同,我如何在微调器中调用
GetCountryCode()
方法

public class MainActivity extends AppCompatActivity implements AdapterView.OnItemSelectedListener{

    String [] rl;
    String spinnervalue;
    int Position;
    TextView txt;
    String text;
    Spinner spin;
    int conv;
    Object item;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        final Spinner spin = (Spinner) findViewById(R.id.simpleSpinner);     
        rl=this.getResources().getStringArray(R.array.CountryCodes);
        txt =(TextView)findViewById(R.id.txt);
        txt.setText(GetCountryZipCode());



        final Customadapter customAdapter=new Customadapter(getApplicationContext(),rl);
        spin.setAdapter(customAdapter);

    spin.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
          Object item;
          int Position;


            @Override
            public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {



            }

        @Override
            public void onNothingSelected(AdapterView<?> parent) {

            }
        });
      }

    public String GetCountryZipCode(){
        String CountryID="";
        String CountryZipCode="";
        Object item;
        int Position;

        TelephonyManager manager = (TelephonyManager) this.getSystemService(Context.TELEPHONY_SERVICE);
        // getNetworkCountryIso
        CountryID= manager.getSimCountryIso().toUpperCase();
        String[] rl=this.getResources().getStringArray(R.array.CountryCodes);
        for(int i=0;i<rl.length;i++){
            String[] g=rl[i].split(",");
            if(g[1].trim().equals(CountryID.trim())){
                CountryZipCode=g[0];
                break;
            }

        }
        return CountryZipCode;
    }

    //Performing action onItemSelected and onNothing selected
    @Override
    public void onItemSelected(AdapterView<?> parent, View view, int position,long id) {


    }

    @Override
    public void onNothingSelected(AdapterView<?> parent) {


    }

}
公共类MainActivity扩展AppCompativeActivity实现AdapterView.OnItemSelectedListener{ 字符串[]rl; 字符串值; 内部位置; 文本视图; 字符串文本; 旋转器旋转; int conv; 目标项目; @凌驾 创建时受保护的void(Bundle savedInstanceState){ super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); 最终微调器旋转=(微调器)findViewById(R.id.SimpleSpiner); rl=this.getResources().getStringArray(R.array.CountryCodes); txt=(TextView)findViewById(R.id.txt); setText(GetCountryZipCode()); 最终的Customadapter=新的Customadapter(getApplicationContext(),rl); spin.setAdapter(customAdapter); spin.setOnItemSelectedListener(新的AdapterView.OnItemSelectedListener(){ 目标项目; 内部位置; @凌驾 已选择公共视图(AdapterView父视图、视图视图、整型位置、长id){ } @凌驾 未选择公共无效(AdapterView父级){ } }); } 公共字符串GetCountryZipCode(){ 字符串CountryID=“”; 字符串CountryZipCode=“”; 目标项目; 内部位置; TelephonyManager=(TelephonyManager)this.getSystemService(Context.TELEPHONY_服务); //getNetworkCountryIso CountryID=manager.getSimCountryIso().toUpperCase(); String[]rl=this.getResources().getStringArray(R.array.CountryCodes); 对于(int i=0;i父级){ } }
公共类MainActivity扩展AppCompativeActivity实现AdapterView.OnItemSelectedListener{

String [] rl;
String spinnervalue;
int Position;
TextView txt;
String text;
Spinner spin;
int conv;
Object item;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    spin = (Spinner) findViewById(R.id.simpleSpinner);     
    rl=this.getResources().getStringArray(R.array.CountryCodes);
    txt =(TextView)findViewById(R.id.txt);
    txt.setText(GetCountryZipCode());



    final Customadapter customAdapter=new Customadapter(getApplicationContext(),rl);
    spin.setAdapter(customAdapter);

    GetCountryZipCode();

spin.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {

        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {



        }

    @Override
        public void onNothingSelected(AdapterView<?> parent) {

        }
    });
  }

public String GetCountryZipCode(){
    String CountryID="";
    String CountryZipCode="";
    Object item;
    int Position;

    TelephonyManager manager = (TelephonyManager) this.getSystemService(Context.TELEPHONY_SERVICE);
    // getNetworkCountryIso
    CountryID= manager.getSimCountryIso().toUpperCase();
    String[] rl=this.getResources().getStringArray(R.array.CountryCodes);
    for(int i=0;i<rl.length;i++){
        String[] g=rl[i].split(",");
        if(g[1].trim().equals(CountryID.trim())){
            CountryZipCode=g[0];
            spin.setSelection(i);
            break;
        }

    }
    return CountryZipCode;
}

//Performing action onItemSelected and onNothing selected
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position,long id) {


}

@Override
public void onNothingSelected(AdapterView<?> parent) {


}
String[]rl;
字符串值;
内部位置;
文本视图;
字符串文本;
旋转器旋转;
int conv;
目标项目;
@凌驾
创建时受保护的void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
spin=(微调器)findViewById(R.id.simpleSpiner);
rl=this.getResources().getStringArray(R.array.CountryCodes);
txt=(TextView)findViewById(R.id.txt);
setText(GetCountryZipCode());
最终的Customadapter=新的Customadapter(getApplicationContext(),rl);
spin.setAdapter(customAdapter);
GetCountryZipCode();
spin.setOnItemSelectedListener(新的AdapterView.OnItemSelectedListener(){
@凌驾
已选择公共视图(AdapterView父视图、视图视图、整型位置、长id){
}
@凌驾
未选择公共无效(AdapterView父级){
}
});
}
公共字符串GetCountryZipCode(){
字符串CountryID=“”;
字符串CountryZipCode=“”;
目标项目;
内部位置;
TelephonyManager=(TelephonyManager)this.getSystemService(Context.TELEPHONY_服务);
//getNetworkCountryIso
CountryID=manager.getSimCountryIso().toUpperCase();
String[]rl=this.getResources().getStringArray(R.array.CountryCodes);
对于(int i=0;i父级){
}

}

您可以从下面的链接获取问题的帮助