我怎么能传递一个字符串值,已在if语句中被创建,通过捆绑的另一个if语句里面呢? [英] How can i pass a string value, that has been created in an if statement, through a bundle inside another if statement?

查看:140
本文介绍了我怎么能传递一个字符串值,已在if语句中被创建,通过捆绑的另一个if语句里面呢?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

public class MainActivity extends Activity implements OnClickListener, AdapterView.OnItemSelectedListener, OnCheckedChangeListener{

@Override
public void onCreate(Bundle icicle) {
    super.onCreate(icicle);
    setContentView(R.layout.main);

    //Declare Variables to be used
    final Bundle bundle = new Bundle();
    final CheckBox checkbox01 = (CheckBox) findViewById(R.id.CheckBox01);


    //All if statements for builds
    final Button findbuilds = (Button) findViewById(R.id.btn_FindBuildsTab1);{
        findbuilds.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                 if ((v==findbuilds)&&(checkbox01.getText()==("Ahri-AP"))&&((checkbox01).isChecked())){
                     final String charactername = "Ahri-AP";
                 }
                 if ((checkbox01).isChecked(){
                   //All Bundles are placed here
                     bundle.putString("CharacterName Value Key", charactername);

                   //Start Tabhost Activity and pass bundle(s)
                     Intent nextActivity = new Intent(v.getContext(),
                     nextActivity.putExtras(bundle);
                     startActivity(nextActivity); TabHostActivity.class);
                 }

基本上,我试图做的是创建在第一个if语句的人物的名字字符串,然后在另一个if语句捆绑它。究其原因,我需要捆绑在一个不同的字符串(S)if语句是为了避免达到一个方法的字节限制。我总共有64种不同的字符串需要被捆绑的每个if语句,和我一共有126 if语句需要发生。这个问题当然是该字符串变量是从来没有发现,或在第二if语句同捆解决的。有没有办法做到这一点?或者,也许更有效的方式?在此先感谢您的帮助! :)

Basically, what i am trying to do is create the string for the character's name in the first if-statement, and then bundle it in another if-statement. The reason i need to bundle the string(s) in a different if-statement is to avoid reaching the bytes limit of a method. I have a total of 64 different Strings that need to be bundled for each if-statement, and i have a total of 126 if-statements that need to happen. The problem is of course that the String variable is never found or resolved with the bundle in the 2nd if-statement. Is there a way to do this? Or maybe a more efficient way? Thanks in advance for the help! :)

推荐答案

只要把你的变量if语句之外的定义。例如:

Just pull the definition of your variable outside of the if statement. eg:

final String charactername 
if() {
    charactername = ...
}
if() {
    bundle stuff with charactername 
}

这篇关于我怎么能传递一个字符串值,已在if语句中被创建,通过捆绑的另一个if语句里面呢?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆