Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/211.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java androideclipse中的屏幕切换_Java_Android_Eclipse - Fatal编程技术网

Java androideclipse中的屏幕切换

Java androideclipse中的屏幕切换,java,android,eclipse,Java,Android,Eclipse,上面的emulator图像只是将给定的两个值相加,并在同一屏幕上的下面的textview上显示结果 这里我需要的是我只想在另一个屏幕的文本视图上显示结果。如何实现 这我必须在我的源上添加什么源 public class CheckingActivity extends Activity { Button button1; EditText txtbox1,txtbox2; TextView tv; /** Called when the activity is first

上面的emulator图像只是将给定的两个值相加,并在同一屏幕上的下面的textview上显示结果

这里我需要的是我只想在另一个屏幕的文本视图上显示结果。如何实现 这我必须在我的源上添加什么源

public class CheckingActivity extends Activity {
 Button     button1;
 EditText   txtbox1,txtbox2;
 TextView tv;

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


     txtbox1=  (EditText) findViewById(R.id.editText1);
     button1 = (Button) findViewById(R.id.button1);
     tv = (TextView) findViewById(R.id.textView5);
     txtbox2=  (EditText) findViewById(R.id.editText2);
     button1.setOnClickListener(new View.OnClickListener() {

    public void onClick(View v) 
    {
         String a,b;
         Integer vis;
         a =  txtbox1.getText().toString();
         b =  txtbox2.getText().toString();    
         vis =  Integer.parseInt(a)+Integer.parseInt(b);
         tv.setText(vis.toString());
        }
    });

非常感谢

如果我正确理解您的意思,您希望显示一个带有结果值的新活动。如果是这样,您可以通过创建一个新活动并向该活动传递一个整数值来完成此操作

您可以这样做:

在检查活动活动中:

public void onClick(View v) 
{
     String a,b;
     Integer vis;
     a =  txtbox1.getText().toString();
     b =  txtbox2.getText().toString();    
     vis =  Integer.parseInt(a)+Integer.parseInt(b);
     Intent in = new Intent(this, B.class);
     in.putExtra("output_value", vis);
     startActivity(in);

    }
});
<RelativeLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">

    <TextView
        android:id="@+id/txt_sum"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Output: "/>

    <TextView
        android:id="@+id/txt_value"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_toRightOf="@id/txt_sum"/>
</RelativeLayout>
    Bundle extras = getIntent().getExtras();
    int value = extras.getInt("output_value");

    TextView output =  (TextView) findViewById(R.id.txt_value);
    output.setText(value);
用于新活动的Xml:

public void onClick(View v) 
{
     String a,b;
     Integer vis;
     a =  txtbox1.getText().toString();
     b =  txtbox2.getText().toString();    
     vis =  Integer.parseInt(a)+Integer.parseInt(b);
     Intent in = new Intent(this, B.class);
     in.putExtra("output_value", vis);
     startActivity(in);

    }
});
<RelativeLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">

    <TextView
        android:id="@+id/txt_sum"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Output: "/>

    <TextView
        android:id="@+id/txt_value"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_toRightOf="@id/txt_sum"/>
</RelativeLayout>
    Bundle extras = getIntent().getExtras();
    int value = extras.getInt("output_value");

    TextView output =  (TextView) findViewById(R.id.txt_value);
    output.setText(value);

如果我正确理解您的意思,那么您希望使用结果值显示一个新活动。如果是这样,您可以通过创建一个新活动并向该活动传递一个整数值来完成此操作

您可以这样做:

在检查活动活动中:

public void onClick(View v) 
{
     String a,b;
     Integer vis;
     a =  txtbox1.getText().toString();
     b =  txtbox2.getText().toString();    
     vis =  Integer.parseInt(a)+Integer.parseInt(b);
     Intent in = new Intent(this, B.class);
     in.putExtra("output_value", vis);
     startActivity(in);

    }
});
<RelativeLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">

    <TextView
        android:id="@+id/txt_sum"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Output: "/>

    <TextView
        android:id="@+id/txt_value"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_toRightOf="@id/txt_sum"/>
</RelativeLayout>
    Bundle extras = getIntent().getExtras();
    int value = extras.getInt("output_value");

    TextView output =  (TextView) findViewById(R.id.txt_value);
    output.setText(value);
用于新活动的Xml:

public void onClick(View v) 
{
     String a,b;
     Integer vis;
     a =  txtbox1.getText().toString();
     b =  txtbox2.getText().toString();    
     vis =  Integer.parseInt(a)+Integer.parseInt(b);
     Intent in = new Intent(this, B.class);
     in.putExtra("output_value", vis);
     startActivity(in);

    }
});
<RelativeLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">

    <TextView
        android:id="@+id/txt_sum"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Output: "/>

    <TextView
        android:id="@+id/txt_value"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_toRightOf="@id/txt_sum"/>
</RelativeLayout>
    Bundle extras = getIntent().getExtras();
    int value = extras.getInt("output_value");

    TextView output =  (TextView) findViewById(R.id.txt_value);
    output.setText(value);
1.)用以下内容替换您的主要活动:

public class CheckingActivity extends Activity {
 Button     button1;
 EditText   txtbox1,txtbox2;
 TextView tv;

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

 txtbox1=  (EditText) findViewById(R.id.editText1);
 button1 = (Button) findViewById(R.id.button1);
 tv = (TextView) findViewById(R.id.textView5);
 txtbox2=  (EditText) findViewById(R.id.editText2);
 button1.setOnClickListener(new View.OnClickListener() {

public void onClick(View v) 
{
     String a,b;
     Integer vis;
     a =  txtbox1.getText().toString();
     b =  txtbox2.getText().toString();    
     vis =  Integer.parseInt(a)+Integer.parseInt(b);
     //tv.setText(vis.toString());
     Intent i = new Intent(getApplicationContext(),ResultActivity.class);
     i.putExtra("sum",vis.toString());
     startActivity(i);
    }

3.)添加一个xml布局文件
resultview

<RelativeLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <TextView
        android:id="@+id/tvsum"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
            android:text="Sum : " />

    <TextView
        android:id="@+id/tvres"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_toRightOf="@id/tvsum"/>
</RelativeLayout>
1.)用以下内容替换您的主要活动:

public class CheckingActivity extends Activity {
 Button     button1;
 EditText   txtbox1,txtbox2;
 TextView tv;

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

 txtbox1=  (EditText) findViewById(R.id.editText1);
 button1 = (Button) findViewById(R.id.button1);
 tv = (TextView) findViewById(R.id.textView5);
 txtbox2=  (EditText) findViewById(R.id.editText2);
 button1.setOnClickListener(new View.OnClickListener() {

public void onClick(View v) 
{
     String a,b;
     Integer vis;
     a =  txtbox1.getText().toString();
     b =  txtbox2.getText().toString();    
     vis =  Integer.parseInt(a)+Integer.parseInt(b);
     //tv.setText(vis.toString());
     Intent i = new Intent(getApplicationContext(),ResultActivity.class);
     i.putExtra("sum",vis.toString());
     startActivity(i);
    }

3.)添加一个xml布局文件
resultview

<RelativeLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <TextView
        android:id="@+id/tvsum"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
            android:text="Sum : " />

    <TextView
        android:id="@+id/tvres"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_toRightOf="@id/tvsum"/>
</RelativeLayout>

另一个屏幕在哪里?解释你的问题另一个屏幕在哪里?解释你的问题problem@OfirAN只是一些字符串来标识值,这样我就可以在新活动中获得他的值。只要您在新活动中使用完全相同的字符串获取值,您就可以将您喜欢的任何内容替换为该字符串。@andro prabu要传递给新活动的值,例如上面示例中的输出值-144。您的意思是,我只是从用户处获取输入值并在textview中显示它,所以我必须提到textview的对象名而不是“yourIntValue”,对吗?@andro prabu更新我的答案。您需要使用所需的textView创建一个新活动。然后将a+b值从onClick事件传递到新活动。在新活动中,您需要使用Bundle获取新值,并使用该值设置textView。@andro prabu更新了我的答案。@只需使用一些字符串来标识该值,这样我就可以在新活动中获取他的值。只要您在新活动中使用完全相同的字符串获取值,您就可以将您喜欢的任何内容替换为该字符串。@andro prabu要传递给新活动的值,例如上面示例中的输出值-144。您的意思是,我只是从用户处获取输入值并在textview中显示它,所以我必须提到textview的对象名而不是“yourIntValue”,对吗?@andro prabu更新我的答案。您需要使用所需的textView创建一个新活动。然后将a+b值从onClick事件传递到新活动。在新活动中,您需要使用Bundle获取新值,并使用该值设置textView。@andro prabu更新了我的答案。如果我遵循了您的来源,则在ResultActivity上,下一行显示错误tv.setText(result);GAMA先生工作正常。非常感谢您提供此解决方案。非常感谢您如果我遵循了您的来源,在ResultActivity上,下面一行显示错误,tv.setText(result);GAMA先生,工作正常。非常感谢您提供此解决方案。非常感谢