0

4 개의 액티비티가 있습니다.TAB로 값 이전 액티비티

제 활성을 입력 데이터로 사용하고, 두번째 작업은 각 탭 활동을 선언 탭 주요 활동 (TabActivity 확장)이고, 3, 4 활동 탭 활동이다.

어떻게 세 번째와 네 번째 활동에 첫 번째 활동에서 값을 전송할 수 있습니다 ?

여기 내 첫번째 활동이다 :

public class FirstActivity extends Activity { 
    EditText inputName; 
    EditText inputAddress; 

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

    //declaration layout 
    inputName = (EditText) findViewById(R.id.editText1); 
    inputAddress = (EditText) findViewById(R.id.editText2); 
    Button btnNextScreen = (Button) findViewById(R.id.button1); 

    //Listening to button event 
    btnNextScreen.setOnClickListener(new View.OnClickListener() { 

     public void onClick(View arg0) { 
     //Starting a new Intent 
     Intent nextScreen = new Intent(getApplicationContext(), MainTabActivity.class); 


     //Sending data to another Activity 
     //THIS IS THE VALUE I WANNA TRANSFER TO TAB ACTIVITY 
     nextScreen.putExtra("name", inputName.getText().toString()); 
     nextScreen.putExtra("address", inputEmail.getText().toString()); 

     // starting new activity 
     startActivity(nextScreen); 

     } 
    }); 
    } 
} 

여기 내 MainTabActivity입니다 :

public class MainTabActivity extends TabActivity { 

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


    Resources res = getResources(); // Resource object to get Drawables 
    TabHost tabHost = getTabHost(); // The activity TabHost 
    TabHost.TabSpec spec; // Resusable TabSpec for each tab 
    Intent intent; // Reusable Intent for each tab 

    // Create an Intent to launch an Activity for the tab (to be reused) 
    intent = new Intent().setClass(this, InfoTab.class); 
    // Initialize a TabSpec for each tab and add it to the TabHost 
    spec = tabHost.newTabSpec("info").setIndicator("Info", 
         res.getDrawable(R.drawable.iconinfotab)) 
        .setContent(intent); 
    tabHost.addTab(spec); 

    // Do the same for the other tabs 
    intent = new Intent().setClass(this, MenuTab.class); 
    spec = tabHost.newTabSpec("menu").setIndicator("Menu", 
         res.getDrawable(R.drawable.iconmenutab)) 
        .setContent(intent); 
    tabHost.addTab(spec); 

    tabHost.setCurrentTab(2); 
    } 
} 

여기 내 3 4 활동이다 (나는 각 활동에 텍스트 뷰하기 전에 이전 값을 표시 싶어) :

public class InfoTab extends Activity { 

    public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.infotab); 

    TextView txtname = (TextView) findViewById(R.id.textTEST1); 
    TextView txtaddress = (TextView) findViewById(R.id.TextTEST2); 


    //displaying data from previous activity 
    //this is didnt work 
    Intent i = getIntent(); 
    // Receiving the Data 
    String name = i.getStringExtra("name"); 
    String address = i.getStringExtra("address"); 

    // Displaying Received data 
    //this is didnt work 
    txtname.setText(name); 
    txtaddress.setText(address); 
    } 
} 

누구든지 나를 도울 수 있습니까 ?? 내가 firts 활동에이 작업을 수행하려고했습니다!

Intent nextScreen = new Intent(getApplicationContext(), InfoTab.class); 

작동 (값이 nextactivity에 옮겨진 대신 탭에서 활동을 개방 할 수있다, 활동 개방 개별적으로 (안 탭) .. .

그래서 여기 내 목표는 각 탭 활동에 가치를 전달하는 것입니다 그들은 MainTabActivity 아래 개방하고 있습니다.

죄송합니다, 좀 작은 실수에 있다고 생각하면 내 영어 밤은 좋아.

+0

누구든지 나를 도울 수 있습니까 ?? –

+0

해결 되었습니까? 나는 또한 문제에 직면하고있다. –

답변

0

당신의 코드.하지만 나는 생각할 수 없다. 그것.

다음은 내가 당신이 원하는 같은 일을하고있는 내 tabActivity의 코드입니다.

public class MyTabActivity extends TabActivity { 
    TabHost myTabHost; 
    String data1, data2, data3; 

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

     Intent i = getIntent(); 
     data1 = i.getStringExtra("Data1"); 
     data2 = i.getStringExtra("Data2"); 
     data3 = i.getStringExtra("Data3"); 

     setTabs(); 
    } 

    @Override 
    public boolean onCreateOptionsMenu(Menu menu) { 
     getMenuInflater().inflate(R.menu.my_tab_activity, menu); 
     return true; 
    } 

    public void setTabs() { 
     myTabHost = getTabHost(); 
     addTab(R.string.tab1Txt, R.drawable.video); 
     addTab(R.string.tab2Txt, R.drawable.pdf); 
     addTab(R.string.tab3Txt, R.drawable.notepad); 
     myTabHost.setCurrentTab(2); 
    } 

    public void addTab(int labelId, int drawableId) { 
     Intent tabIntent = null; 
     TabHost.TabSpec spec; 
     switch (labelId) { 
     case R.string.tab1Txt: 
      tabIntent = new Intent(this, Tab1Activity.class); 
      tabIntent.putExtra("Data", data1); 
      break; 
     case R.string.tab2Txt: 
      tabIntent = new Intent(this, Tab2Activity.class); 
      tabIntent.putExtra("Data", data2); 
      break; 
     case R.string.tab3Txt: 
      tabIntent = new Intent(this, Tab3Activity.class); 
      tabIntent.putExtra("Data", data3); 
      break; 
     } 

     spec = myTabHost.newTabSpec("tab" + labelId); 
     View tabIndicator = LayoutInflater.from(this).inflate(
       R.layout.indicator, getTabWidget(), false); 

     TextView title = (TextView) tabIndicator.findViewById(R.id.title); 
     title.setText(labelId); 
     title.setTextColor(Color.BLUE); 
     ImageView img = (ImageView) tabIndicator.findViewById(R.id.icon); 
     img.setImageResource(drawableId); 
     spec.setIndicator(tabIndicator); 
     spec.setContent(tabIntent); 
     myTabHost.addTab(spec); 
    } 
} 

희망이 있습니다.

관련 문제