Hello, how to combine 2 codes into one. Conflict of one class name. Need Fragment and Activity. public class Set1 extends Fragment

public class Set1 extends Activity

1 part

public class Set1 extends Fragment { @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View set1 = inflater.inflate(R.layout.set1_frag, container, false); return set1; }} 

2 part of the code (must be combined with 1)

 public class Set1 extends Activity { Button btnLogout; Button changepas; /** * Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); changepas = (Button) findViewById(R.id.btchangepass); btnLogout = (Button) findViewById(R.id.logout); DatabaseHandler db = new DatabaseHandler(getApplicationContext()); /** * Hashmap to load data from the Sqlite database **/ HashMap<String,String> user = new HashMap<String, String>(); user = db.getUserDetails(); /** * Change Password Activity Started **/ changepas.setOnClickListener(new View.OnClickListener(){ public void onClick(View arg0){ Intent chgpass = new Intent(getApplicationContext(), ChangePassword.class); startActivity(chgpass); } }); /** *Logout from the User Panel which clears the data in Sqlite database **/ btnLogout.setOnClickListener(new View.OnClickListener() { public void onClick(View arg0) { UserFunctions logout = new UserFunctions(); logout.logoutUser(getApplicationContext()); Intent login = new Intent(getApplicationContext(), Login.class); login.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); startActivity(login); finish(); } }); /** * Sets user first name and last name in text view. **/ final TextView login = (TextView) findViewById(R.id.textwelcome); login.setText("Welcome "+user.get("fname")); final TextView lname = (TextView) findViewById(R.id.lname); lname.setText(user.get("lname")); }} 

Update

I will try to explain in detail and normally. I had two parts of the code, I combined them. it was registration and menu (top menu), then I created 4 submenus (main, main, spare, settings). The problem arose from the submenu - settings. Copied .xml registration settings code. I decided to combine the code that relates to the menu with the registration settings. But I got stuck with a problem. If you rename Fragment into Activity, then a lot of errors come out. I can not combine it. By this turned for help laying out fragments of the application.

  • one
    Please clarify what the problem is or provide additional information to clarify exactly what the question is. Now it is almost impossible to understand what exactly you are asking. To find out how to properly formulate questions, visit the "How to Ask Questions" page. - Regent
  • It is necessary to combine these 2 codes into one. The problem is that when connecting 2 projects, an error occurred about duplicating the class. - OxGen
  • If I understand correctly, in one of the projects, the refactoring will change the class name to one that is not repeated in another project, although your question is more than completely incomprehensible. - pavlofff 4:05 pm
  • one
    There is a menu (code snippet - part 1), I want to insert a second part into it, so that the buttons are clickable. - OxGen pm
  • Do you want to insert something into the fragment? The more you try to explain something, the more incomprehensible it becomes. If you need to work out the logic of clicks, why insert something somewhere - just write the code and that's it. business for a minute. I can not comprehend how you get the coincidence of class names, if you need logic for clicks? You insert the activation code into the fragment or something where ... write what you got in the end or something like that. - pavlofff

1 answer 1

If you want 2 classes with the same name to coexist in the same application, decompose them into packages.

For example, the application package com.mydomain.mobile.myapp , there will be an Activity , a Fragment move to com.mydomain.mobile.myapp.fragments .

This question to Android Studio, and to Android is not relevant.