Java 将静态字符串值传递给textview

Java 将静态字符串值传递给textview,java,android,string,Java,Android,String,我将各种活动中的值存储在静态字符串中。我尝试通过以下操作来显示这些内容: TextView t = (TextView) findViewById(R.id.text_view); t.setText(static_String); 当我在另一项活动中做了完全相同的事情时,它起了作用。现在,文本视图没有显示任何内容 代码如下: import static com.miniproject32.writeup.S12.scene0; import static com.miniproject32.

我将各种活动中的值存储在静态字符串中。我尝试通过以下操作来显示这些内容:

TextView t = (TextView) findViewById(R.id.text_view);
t.setText(static_String);
当我在另一项活动中做了完全相同的事情时,它起了作用。现在,文本视图没有显示任何内容

代码如下:

import static com.miniproject32.writeup.S12.scene0;
import static com.miniproject32.writeup.S16.scene1a;
import static com.miniproject32.writeup.S16.scene1b;
import static com.miniproject32.writeup.S16.scene1c;
import static com.miniproject32.writeup.S16.scene1d;
import static com.miniproject32.writeup.S16.scene1e;
import static com.miniproject32.writeup.S19.resolution;
import static com.miniproject32.writeup.S19.scene2a;
import static com.miniproject32.writeup.S19.scene2b;
import static com.miniproject32.writeup.S19.scene2c;
import static com.miniproject32.writeup.S19.scene2d;
import static com.miniproject32.writeup.S19.scene2e;

//scene editor: generate one for each scene from outline in a sequential order. 
//Store scenes in files. These can be accessed and viewed from home screen
public class S21 extends AppCompatActivity {
int sceneno;
TextView t1,t2;
EditText e;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.editor);

    Toolbar toolbar = (Toolbar)findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

    Bundle extras = getIntent().getExtras();
    if (extras != null) {
        sceneno = extras.getInt("Scene no ");
        //The key argument here must match that used in the other activity
    }
    else
        sceneno=1;

    Typeface tf = Typeface.createFromAsset(getAssets(),"font.ttf");

    t1 = (TextView) findViewById(R.id.editor_scene_label);
    t2 = (TextView) findViewById(R.id.editor_scene_val);

        switch (sceneno) {
            case 1:
                t1.setText(R.string.scene_0);
                t2.setText(scene0);
                break;
            case 2:
                t1.setText(R.string.scene_1a);
                t2.setText(scene1a);
                break;
            case 3:
                t1.setText(R.string.scene_1b);
                t2.setText(scene1b);
                break;
            case 4:
                t1.setText(R.string.scene_1c);
                t2.setText(scene1c);
                break;
            case 5:
                t1.setText(R.string.scene_1d);
                t2.setText(scene1d);
                break;
            case 6:
                t1.setText(R.string.scene_1e);
                t2.setText(scene1e);
                break;
            case 7:
                t1.setText(R.string.scene_2a);
                t2.setText(scene2a);
                break;
            case 8:
                t1.setText(R.string.scene_2b);
                t2.setText(scene2b);
                break;
            case 9:
                t1.setText(R.string.scene_2c);
                t2.setText(scene2c);
                break;
            case 10:
                t1.setText(R.string.scene_2d);
                t2.setText(scene2d);
                break;
            case 11:
                t1.setText(R.string.scene_2e);
                t2.setText(scene2e);
                break;
            case 12:
                t1.setText(R.string.resolution);
                t2.setText(resolution);
                break;

        }

    Button b=(Button) findViewById(R.id.but_editor);
    b.setText(R.string.done);
    b.setTypeface(tf);
}

public void writeStringAsFile(final String fileContents, String fileName) {
     try {
         FileWriter out = new FileWriter(new File(this.getFilesDir(), fileName));
         out.write(fileContents);
         out.close();
     }
     catch (IOException e) {
        e.printStackTrace();
     }
}

public void nextScreen(View view){
    //on click:
    //save scene
    //show popup/toast saying scene saved
    //move to new blank same screen with scene title different
    e=(EditText) findViewById(R.id.editor_ip);
        switch (sceneno) {
            case 1:
                writeStringAsFile(e.getText().toString(), "Scene1.txt");
                Toast.makeText(this, "Saved", Toast.LENGTH_SHORT).show();
                break;
            case 2:
                writeStringAsFile(e.getText().toString(), "Scene2.txt");
                Toast.makeText(this, "Saved", Toast.LENGTH_SHORT).show();
                break;
            case 3:
                writeStringAsFile(e.getText().toString(), "Scene3.txt");
                Toast.makeText(this, "Saved", Toast.LENGTH_SHORT).show();
                break;
            case 4:
                writeStringAsFile(e.getText().toString(), "Scene4.txt");
                Toast.makeText(this, "Saved", Toast.LENGTH_SHORT).show();
                break;
            case 5:
                writeStringAsFile(e.getText().toString(), "Scene5.txt");
                Toast.makeText(this, "Saved", Toast.LENGTH_SHORT).show();
                break;
            case 6:
                writeStringAsFile(e.getText().toString(), "Scene6.txt");
                Toast.makeText(this, "Saved", Toast.LENGTH_SHORT).show();
                break;
            case 7:
                writeStringAsFile(e.getText().toString(), "Scene7.txt");
                Toast.makeText(this, "Saved", Toast.LENGTH_SHORT).show();
                break;
            case 8:
                writeStringAsFile(e.getText().toString(), "Scene8.txt");
                Toast.makeText(this, "Saved", Toast.LENGTH_SHORT).show();
                break;
            case 9:
                writeStringAsFile(e.getText().toString(), "Scene9.txt");
                Toast.makeText(this, "Saved", Toast.LENGTH_SHORT).show();
                break;
            case 10:
                writeStringAsFile(e.getText().toString(), "Scene10.txt");
                Toast.makeText(this, "Saved", Toast.LENGTH_SHORT).show();
                break;
            case 11:
                writeStringAsFile(e.getText().toString(), "Scene11.txt");
                Toast.makeText(this, "Saved", Toast.LENGTH_SHORT).show();
                break;
            case 12:
                writeStringAsFile(e.getText().toString(), "Scene12.txt");
                Toast.makeText(this, "Saved", Toast.LENGTH_SHORT).show();
                break;

            default:
                break;
        }
    sceneno++;
    Intent intent = new Intent(S21.this,S21.class);
    intent.putExtra("Scene no ",sceneno);
    startActivity(intent);
}

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

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // Handle action bar item clicks here. The action bar will
    // automatically handle clicks on the Home/Up button, so long
    // as you specify a parent activity in AndroidManifest.xml.
    int id = item.getItemId();

    if (id == R.id.action_home){
        Intent i = new Intent(this, Home.class);
        startActivity(i);
    }
    //noinspection SimplifiableIfStatement
    if (id == R.id.action_settings) {
        return true;
    }

    return super.onOptionsItemSelected(item);
}

}

这应该行得通吧?有人能告诉我我遗漏了什么吗?

每次增加sceneno++的值时。所以它最多可以工作12种情况,但在这之后它不会显示任何基于代码概念的内容

   switch (sceneno) {
        case 1:

       .....
        case 12:
            t1.setText(R.string.resolution);
            t2.setText(resolution);
            break;
       default :
            t1.setText("your text");
            t2.setText("your text");
    }

如果有效,则单击勾选并向上投票接受答案