编辑:onClick 现在工作正常。问题是该按钮试图从 Parent 类中触发 onClick。现在这是固定的。当然,这意味着正在发生一个新问题,即永远不会调用 onActivityResult。
所以我不太确定到底发生了什么,当我按下按钮时什么都没有发生,logcat 中什么也没有,什么都没有,好像没有代码一样,但我很确定这是正确的,有什么想法吗?
public class myClass extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.store_selector);
Button getStore = (Button)findViewById(R.id.getStore);
getStore.setOnClickListener(buttonGetStoreOnClickListener);
}
Button.OnClickListener buttonGetStoreOnClickListener
= new Button.OnClickListener(){
public void onClick(View arg0) {
Intent intent = new Intent("com.blah.Blah.client.android.SCAN");
intent.setPackage("com.blah.Blah");
intent.putExtra("com.blah.Blah.client.android.SCAN.SCAN_MODE", "QR_CODE_MODE");
startActivityForResult(intent, 0);
};
};
@Override
public void onActivityResult(int requestCode, int resultCode, Intent intent)
{
if (requestCode == 0)
{
if (resultCode == RESULT_OK)
{
String contents = intent.getStringExtra("SCAN_RESULT");
String format = intent.getStringExtra("SCAN_RESULT_FORMAT");
Log.i("debug tag", "contents: "+contents+" format: "+format);
Intent myIntent = new Intent(this, Ads.class);
myIntent.putExtra("key", contents);
startActivity(myIntent);
setContentView(R.layout.activity_ads);
// Handle successful scan
}
else if (resultCode == RESULT_CANCELED)
{
// Handle cancel
Log.i("xZing", "Cancelled");
}
}
}
};