場所を決定する主な活動が1つあります。このメインアクティビティでは、最初にスプラッシュスクリーンフラグメントを追加します。最初の位置情報/GPSが正しく機能していて位置情報が見つかった時点で、このスプラッシュ画面をメインメニューに置き換えたいと思います。mainactivityの関連コード:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.frame);
//Check that the activity is using the layout version
// the framelayout
if(findViewById(R.id.fragment_container)!=null){
//To avoid overlapping fragments check if we are restored from a state, then we don't have to do anything
if(savedInstanceState != null){
return;
}
Splash splashscr = new Splash();
Main main = new Main();
getSupportFragmentManager().beginTransaction()
.add(R.id.fragment_container, splashscr).commit();
// I **think something should be added here
//to check if a location has been found yet.**
FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
transaction.replace(R.id.fragment_container, main);
transaction.commit();
}
}
その場所にwhile(foundlocation!= true)を追加してみました。次に、foundlocationは、onLocationChanged()またはgetLocation()の最後のいずれかでtrueに設定されます。しかし、それは私の問題を解決しませんでした。誰かが私を助けることができますか?問題を十分に明確にしなかった場合は、そのように言ってください。
編集:Gabeのコメントを検討した後、これを試しました(locationfoundは、アクティビティクラスでfalseとして開始されたパブリックブール値です)。しかし、DDMSを使用して場所を送信すると、スプラッシュ画面が消えることはありません。私が正しければ、最初に場所が変更されたとき、ブール値はまだfalseであるため、フラグメントを切り替える必要があります。ifステートメントなしで試してみましたが、機能していました。ここで何を忘れますか?
public void onLocationChanged(final Location location) {
if(locationfound=false)
{
//Some irrelevant code about saving the new location
Main main = new Main();
FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
transaction.replace(R.id.fragment_container, main);
transaction.commit();
locationfound=true;
}
//changing value of sometextboxes in the Main fragment
}