0

我的应用程序有 3 个选项卡。在这个选项卡中有多个活动(意味着此选项卡具有到子选项卡的导航)。我在一个子活动中使用了 startActivityforResult()。但控制永远不会转到 onActivityResult() 方法。如何实现这一点。请任何人都可以帮助我。

代码

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
 }
}   

//活动_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();           
    }       
};  
}   
4

2 回答 2

0
getParent().startActivityForResult(yourNewIntent, yourResult);
于 2013-09-06T20:30:47.023 回答
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);    
    }
}
于 2012-04-13T12:48:04.423 回答