嗨其他编码员我真的需要帮助,我真的没有想法,尝试了很多想法,没有人为我工作....
我正忙于排放调查应用程序,我正在尝试更改if语句中的标签,如果广播的值为1,则转到第二个标签,然后自动到第三个...附件是片段,请帮忙,我真的很感激....!
第一张图片是我将数据发送回第一个标签 (目前所有人仍在工作)
loadB.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
TabActivity tabs = (TabActivity) getParent();
tabs.getTabHost().setCurrentTab(0);
sendData3();
}
private void sendData3() {
take = "1";
Intent dataIntent = new Intent();
dataIntent.setAction("com.example.e3soft.receiver");
dataIntent.putExtra("taken", take);
sendBroadcast(dataIntent);
Toast.makeText(getBaseContext(), "Working", Toast.LENGTH_LONG).show();
}
});
如果没有if语句一切正常,请帮助........!
private void receiveData() {
// TODO Auto-generated method stub
BroadcastReceiver receiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
// TODO Auto-generated method stub
take = intent.getStringExtra("taken");
}
};
IntentFilter filter = new IntentFilter();
filter.addAction("com.example.e3soft.receiver");
registerReceiver(receiver, filter);
changeTab();
}
protected void changeTab() {
// TODO Auto-generated method stub
Toast.makeText(getApplicationContext(), take, Toast.LENGTH_LONG).show();
try {
if (take.equals("1")) {
populateVariables();
TabActivity tabs = (TabActivity) getParent();
tabs.getTabHost().setCurrentTab(1);
sendData();
}
} catch (Exception ex) {
Toast.makeText(getApplicationContext(), "Error", Toast.LENGTH_LONG)
.show();
}
}
答案 0 :(得分:0)
将此代码移到onReceive中:
IntentFilter filter = new IntentFilter();
filter.addAction("com.example.e3soft.receiver");
registerReceiver(receiver, filter);
changeTab();