0

私はandroidのself_learnerです。

2つの画面があります。最初の画面には1つの編集テキストとボタンが含まれています。編集テキストはユーザーからの入力を取得し、ボタンは2番目の画面にあるタブホストのアクティビティを呼び出すためのものです。

実行時に、ユーザーからの入力を取得した後、2番目の画面にあるタブホストのタブのいずれかに適切な値を(ユーザーの入力に従って)表示する必要があります。

しかし、ここでの私の問題は、タブホスト形式ではなく、別の画面に回答が表示されることです。

注:以下のコードでは、共有設定を使用してデータを保存してtabhostに表示することにのみ問題があると思います。誰か助けてもらえますか?

以下のコードを見つけてください

Demo_tabActivity.java

  public class Demo_tabActivity extends Activity 
     {

private static String NAMESPACE = "http://tempuri.org/";
   private static String METHOD_NAME = "FahrenheitToCelsius";
   private static String SOAP_ACTION = "http://tempuri.org/FahrenheitToCelsius";
   private static String URL = "http://www.w3schools.com/webservices/tempconvert.asmx?WSDL";

   Button btnFar;
   EditText txtFar,txtshow;


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

       txtFar = (EditText)findViewById(R.id.editText_in);

       btnFar = (Button)findViewById(R.id.button1);
       btnFar.setOnClickListener(new View.OnClickListener()
       {
       public void onClick(View v)
       {
           String b;

         //Initialize soap request + add parameters
         SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);       

         //Use this to add parameters
         request.addProperty("Fahrenheit",txtFar.getText().toString());

         //Declare the version of the SOAP request
         SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);

         envelope.setOutputSoapObject(request);
         envelope.dotNet = true;

         try 
         {   
             HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);

             //this is the actual part that will call the webservice
             androidHttpTransport.call(SOAP_ACTION, envelope);

             // Get the SoapResult from the envelope body.

             SoapPrimitive result = (SoapPrimitive)envelope.getResponse();

             SharedPreferences sharedPreferences;
              sharedPreferences=PreferenceManager.getDefaultSharedPreferences(Demo_tabActivity.this);
             Editor editor = sharedPreferences.edit();
             editor.putString("your", "b");
             editor.commit();

             if(result != null)
             {
                 b=result.toString();
                 Intent i = new Intent(getApplicationContext(),Tab_1.class);
                 i.putExtra("goto", b.toString());
                 startActivity(i);
             }
             else
             {
                 Toast.makeText(getApplicationContext(), "oops!..empty",Toast.LENGTH_SHORT).show();
             }

           }
         catch (Exception e)
         {
           e.printStackTrace();
           }
         }
       });   

   }
 }

Tab_1.java

   public class Tab_1 extends Activity 
    {
EditText tv;
String result;


     /** Called when the activity is first created. */

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.tab1);

SharedPreferences sharedPreferences;
sharedPreferences = PreferenceManager.getDefaultSharedPreferences(Tab_1.this);
String answer= sharedPreferences.getString("your","");

Bundle extras = getIntent().getExtras();

if(extras !=null)
{
    result = extras.getString("goto");

}
tv=(EditText)findViewById(R.id.editText_output);
tv.setText(result);
}
  }

貴重な時間をありがとうございました!

4

1 に答える 1

1

わかった。最初に簡単に説明させてください。

startActivity() を呼び出すと、単に Activity クラスを呼び出そうとしていることを意味します。ただし、移動先のすべての画面でタブ バーを使用できるというわけではありません。タブは tabActivity に関連しているため、通常のアクティビティとは完全に分離されています。したがって、すべてのページでタブを表示するには、ビューを置き換えて同じ tabActivity にとどめる必要があります。

So the first step is to get the next activity which you want to display as a view and add it to the tabs. This is what Activity Group is emant to do. Here is a very good example of how to understand ActivityGroup.

ActivityGroup Example

To make this more easier, Fragments are introduced. it does the same operation as Activity Group(to replace views). here are few examples,

http://android.codeandmagic.org/2011/07/android-tabs-with-fragments/

http://developer.android.com/resources/samples/Support4Demos/src/com/example/android/supportv4/app/FragmentTabs.html

于 2012-06-21T06:38:28.167 に答える