Vote count:
0
I have to call a fragment class from an activity. In the activity, i have to check the username and password before calling the fragment class. When i click the login button, fragment class has to be loaded. But, login layout is overlapped by the fragment layout. How to remove the overlapping.
login.java
public class Login extends Activity {
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.login);
}
public void evaluate(View view){
EditText editText1 = (EditText) findViewById(R.id.editText1);
EditText editText2 = (EditText) findViewById(R.id.editText2);
String username = editText1.getText().toString();
String password = editText2.getText().toString();
if (username.equals("user") && password.equals("user")){
Fragment1 fragment1 = new Fragment1();
getFragmentManager().beginTransaction()
.add(android.R.id.content, fragment1).commit();
}
}
}
Fragment1.java
public class Fragment1 extends Fragment{
public View onCreateView(LayoutInflater inflater,
ViewGroup container, Bundle savedInstanceState){
return inflater.inflate(R.layout.fragment1, container,false);
} }
login.xml
<LinearLayout xmlns:android="http://ift.tt/nIICcg"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout android:orientation="horizontal"
android:layout_width="wrap_content"
android:layout_height="fill_parent">
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Username" />
<EditText
android:id="@+id/editText1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10" >
<requestFocus />
</EditText>
</LinearLayout>
<LinearLayout android:orientation="horizontal"
android:layout_width="wrap_content"
android:layout_height="fill_parent">
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Password" />
<EditText
android:id="@+id/editText2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10" >
</EditText>
</LinearLayout>
<Button
android:id="@+id/login"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:onClick="evaluate"
android:text="Login" />
</LinearLayout>
fragment1.xml
<LinearLayout xmlns:android="http://ift.tt/nIICcg"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<Button
android:id="@+id/login"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:onClick="goto"
android:text="Go to Main Activity" />
</LinearLayout>
asked 23 secs ago
how to call a fragment from activity
Aucun commentaire:
Enregistrer un commentaire