Hallo Jungs und Mädels, wenn ich ein Fragment starten die Sicht von meiner Hauptklasse ist immer noch sichtbar daher die Tasten während des gesamten Programms .. Ich frage mich, was die einfachste Lösung für dieses Problem sein könnte. Muss ich ein Fragment für zwei Schaltflächen erstellen und dann ein weiteres Fragment aus dem Fragment mit den Schaltflächen starten? Gibt es eine Möglichkeit, die Ansicht von der Hauptklasse zu verbergen, während das Fragment angezeigt wird? Irgendwelche Tipps werden sehr geschätzt Ich habe eine Lösung für eine Weile jetzt gesucht.MainActivity immer noch sichtbar mit Fragment
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Arrays.sort(lContacts,Contact.ContactNameComparator);
for(int i = 0; i< lContacts.length;i++){
mLnames[i] = lContacts[i].getLname();
}
mQuoteArray = getResources().getStringArray(R.array.Quotes);
setContentView(R.layout.activity_main);
btnnames = (Button) findViewById(R.id.btnlaunch);
btndepartments = (Button) findViewById(R.id.btndepartments);
btnnames.setOnClickListener(myhandler1);
btndepartments.setOnClickListener(myhandler2);
mTitleFrameLayout = (FrameLayout) findViewById(R.id.title_fragment_container);
mQuotesFrameLayout = (FrameLayout) findViewById(R.id.quote_fragment_container);
mFragmentManager = getFragmentManager();
fragmentTransaction = mFragmentManager
.beginTransaction();
mFragmentManager
.addOnBackStackChangedListener(new FragmentManager.OnBackStackChangedListener() {
public void onBackStackChanged() {
setLayout();
}
});
}
View.OnClickListener myhandler1 = new View.OnClickListener() {
public void onClick(View v) {
mFragmentManager = getFragmentManager();
FragmentTransaction fragmentTransaction = mFragmentManager
.beginTransaction();
fragmentTransaction.add(R.id.title_fragment_container,
new TitlesFragment());
fragmentTransaction.commit();
}
};
View.OnClickListener myhandler2 = new View.OnClickListener() {
public void onClick(View v) {
}
};
private void setLayout() {
if (!mQuoteFragment.isAdded()) {
mTitleFrameLayout.setLayoutParams(new LinearLayout.LayoutParams(
MATCH_PARENT, MATCH_PARENT)); // width, height
mQuotesFrameLayout.setLayoutParams(new LinearLayout.LayoutParams(0,
MATCH_PARENT));
} else {
mTitleFrameLayout.setLayoutParams(new LinearLayout.LayoutParams(0,
MATCH_PARENT, 1f)); // width, height, weight
mQuotesFrameLayout.setLayoutParams(new LinearLayout.LayoutParams(0,
MATCH_PARENT, 2f));
}
}
@Override
public void onListSelection(int index) {
if (!mQuoteFragment.isAdded()) {
FragmentTransaction fragmentTransaction = mFragmentManager
.beginTransaction();
fragmentTransaction.add(R.id.quote_fragment_container,
mQuoteFragment);
fragmentTransaction.addToBackStack(null);
fragmentTransaction.commit();
mFragmentManager.executePendingTransactions();
}
if (mQuoteFragment.getShownIndex() != index) {
mQuoteFragment.showIndex(index);
}
}
Ich landete die zwei Tasten auf Mainactivity, dann machte eine leere Aktivität für die Fragmente. Danke für die Vorschläge! – user3264060