Ich bin mit einem seltsamen Problem konfrontiert, ich versuche, eine Aktivität mit 6 Arten von verschiedenen Layouts zu implementieren, nur eine wird auf der Grundlage von Layout-Typ und andere sichtbar sein wird verstecktIch bin nicht in der Lage, Ansichten zu sehen, sobald die Aktivität in Android App
So ist der Fluss ein Handler zeigt jeden Typ/Sicht nach 20 Sekunden und nach sagen n mal die Aktivität beendet.
Nun das Problem ist, wenn ich die Aktivität neu starten Ich bin nicht in der Lage
Layout-Datei eine der Ansichten zu sehen:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout style="@style/RelParent"
android:id="@+id/rel_parent"
xmlns:android="http://schemas.android.com/apk/res/android">
<include
android:id="@+id/rel_1"
layout="@layout/layout_1"/>
<include
android:id="@+id/rel_2"
layout="@layout/layout_2"/>
<include
android:id="@+id/rel_3"
layout="@layout/layout_3"/>
<include
android:id="@+id/rel_4"
layout="@layout/layout_4"/>
<include
android:id="@+id/rel_5"
layout="@layout/layout_5"/>
<include
android:id="@+id/rel_6
layout="@layout/layout_6"/>
</RelativeLayout>
Aktivität Code:
public class ExampleActivity extends AppCompatActivity {
private ArrayList<Model> mModels;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(null);
Log.d(TAG, "onCreate, starting quiz");
initLayoutTypeMap();
hideAllLayouts();
mModels = //getDataFromDB;
mHandler = new Handler();
mHandler.postDelayed(mRunnable, 2000);
}
private void initLayoutTypeMap() {
mTypeLayoutMap = new HashMap<>();
mTypeLayoutMap.put(type1, relType1);
mTypeLayoutMap.put(type2, relType2);
mTypeLayoutMap.put(type3, relType3);
mTypeLayoutMap.put(type4, relType4);
mTypeLayoutMap.put(type5, relType5);
mTypeLayoutMap.put(type6, relType6);
}
private void startNew(int id) {
Model model = mModels.get(id);
showLayout(model.getType);
showLayout(type);
//Do all the data showing on views
}
private void showLayout(String type) {
mTypeLayoutMap.get(type).setVisibility(View.VISIBLE);
}
private Runnable mRunnable = new Runnable() {
@Override
public void run() {
if (id <= mModels.size()) {
hideAllLayouts();
clearAll();
startNew(id);
id++;
mHandler.postDelayed(mRunnable, 20000);
} else {
hideAllLayouts();
mHandler.removeCallbacks(mRunnable);
finish();
}
}
};
}
Für die erste Iteration funktioniert alles wie erwartet. Aber sobald ich diese Tätigkeit beenden und versuchen Sie es erneut zu starten keine Aussicht sichtbar ist
Können Sie bitte Ihren vollständigen Code zeigen? Es gibt einige Methoden, die von Ihrem onCreate() wie hideAllLayouts() fehlen? –