2012-04-13 60 views
0

我的應用程序有3個選項卡。在這個標籤中有多個活動(意味着這個標籤有導航到子標籤)。我在一個小孩活動中使用了startActivityforResult()。但控制永遠不會去onActivityResult()方法。如何實現這一點。請任何人都可以幫助我。android - 如何在標籤中使用startActivityForResult()

代碼

public class Activity_1 extends Activity 
{ 


public void onCreate(Bundle savedInstanceState) 
{ 
    super.onCreate(savedInstanceState); 
    View contentView = LayoutInflater.from(getParent()).inflate(R.layout.static_search_filters, null); 
    setContentView(contentView); 

    states_tv = (TextView)findViewById(R.id.state); 
    states_tv.setOnClickListener(states_etListener);   
} 

private OnClickListener states_etListener = new View.OnClickListener() 
{ 
    public void onClick(View v) 
    {    
     Intent intent = new Intent(getParent(), RB_CategoriesMList.class); 
     intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); 
     startActivityForResult(intent,GET_SEL_STATES_LIST);    
    }  
}; 

protected void onActivityResult(int requestCode, int resultCode, Intent data) 
{ 
     super.onActivityResult(requestCode, resultCode, data);  
     //I do some stuff here 
} 
} 

// Activity_2

public class RB_CategoriesMList extends ListActivity 
{ 



public Button sbtn; 

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

    sbtn =(Button)findViewById(R.id.submit_categories); 
    sbtn.setOnClickListener(sbtn_listener); 
}  

private OnClickListener sbtn_listener = new View.OnClickListener() 
{ 
    public void onClick(View v) 
    { 
     Intent state_intent = getIntent();    
     state_intent.putExtra("selected_states", "");          
     setResult(RESULT_OK,state_intent); 
     finish();   
    }  
}; 
} 
+0

http://stackoverflow.com/questions/1306689/launching-activities-within-a-tab-in-android ......反正你不應該這樣做...它像你的用戶界面不適合Android設計的接縫 – Selvin 2012-04-13 12:39:15

回答

0

不要調用

super.onActivityResult(requestCode, resultCode, data);  

當您收到onActivityResult,檢查請求的代碼是你的,然後做你的東西。在其他情況下,你應該叫超級。

所以:

protected void onActivityResult(int requestCode, int resultCode, Intent data) 
{ 
    if (requestCode == GET_SEL_STATES_LIST) { 
     // Do your stuff 
    } else { 
     super.onActivityResult(requestCode, resultCode, data);  
    } 
} 
0
getParent().startActivityForResult(yourNewIntent, yourResult); 
相關問題