Эй IAM новой для кодирования/Java/Android, пожалуйста, идти просто на меняМножественные виды спорта для макета в приложении входа
Я добавил, если другое заявление на кнопку входа в систему,
if(username = admin && password = admin){
then go to admin activity
}else if(username = manager && password = manager){
then go to manager activity
}else if(username = user && password = user){
then go to user activity
}else{
display text wrong password
}
, когда в админ активность вызывается для кнопки add_user в менеджер активности он требует кнопки ORDER_ITEMS и пользовательской активности вызывается для кнопки sales_report
все кнопки определены в activity_users_area.xml
Issue/Проблема
Проблема, когда я войти в систему как администратор в приложение будет показывать все отображаемые в файле макета activity_users_area.xml кнопки же самое можно сказать, если я войти в систему в качестве менеджера или пользователя
I хотите, чтобы он отображал только то, что вызывалось в соответствующем классе Java, как я могу достичь этого?
Iam, используя тот же макет для администратора и пользователя, потому что в будущем я могу добавить кнопки, которые будут распространены для Admin User и Manager или Admin и Manger и т. д.
пожалуйста, не предложить мне создать базу данных для администратора, пользователя и менеджер ищет вариант, чтобы решить без них
Это то, что мой макет выглядит как activity_users_area.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".AdminAreaActivity">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Add User"
android:id="@+id/bAddUser"
android:layout_alignParentTop="true"
android:layout_alignParentEnd="true"
android:layout_alignParentStart="true" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Remove User"
android:id="@+id/bRemoveUser"
android:layout_below="@+id/bAddUser"
android:layout_alignParentStart="true"
android:layout_alignParentEnd="true" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Change Stock"
android:id="@+id/bChangeStock"
android:layout_below="@+id/bRemoveUser"
android:layout_alignParentStart="true"
android:layout_alignParentEnd="true" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Sales Report"
android:id="@+id/bSalesReport"
android:layout_below="@+id/bChangeStock"
android:layout_alignParentStart="true"
android:layout_alignParentEnd="true" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Change Customer"
android:id="@+id/bChangeCustomer"
android:layout_below="@+id/bChangeStock"
android:layout_alignParentStart="true"
android:layout_alignParentEnd="true" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Collection Report"
android:id="@+id/bCollectionReport"
android:layout_below="@+id/bSalesReport"
android:layout_alignParentStart="true"
android:layout_alignParentEnd="true" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Stock Report"
android:id="@+id/bStockReport"
android:layout_below="@+id/bCollectionReport"
android:layout_alignParentStart="true"
android:layout_alignParentEnd="true" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Pay Collect"
android:id="@+id/bPayCollect"
android:layout_below="@+id/bStockReport"
android:layout_alignParentStart="true"
android:layout_alignParentEnd="true" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Item Sales"
android:id="@+id/bItemSales"
android:layout_below="@+id/bPayCollect"
android:layout_alignParentStart="true"
android:layout_alignParentEnd="true" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Loan Collect"
android:id="@+id/bLoanCollect"
android:layout_below="@+id/bItemSales"
android:layout_alignParentStart="true"
android:layout_alignParentEnd="true" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Order Items"
android:id="@+id/bOrderItems"
android:layout_below="@+id/bLoanCollect"
android:layout_alignParentStart="true"
android:layout_alignParentEnd="true" />
</RelativeLayout>
Это мой LoginActivity.java
package online.klok.mobpos;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
public class LoginActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
final EditText etUsername = (EditText) findViewById(R.id.etUserName);
final EditText etPassword = (EditText) findViewById(R.id.etPassword);
final Button bLogin = (Button) findViewById(R.id.bLogin);
final TextView registerLink = (TextView) findViewById(R.id.tvRegisterHere);
registerLink.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent registerIntent = new Intent(LoginActivity.this, RegisterActivity.class);
LoginActivity.this.startActivity(registerIntent);
}
});
bLogin.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
EditText username = (EditText) findViewById(R.id.etUserName);
EditText password = (EditText) findViewById(R.id.etPassword);
if (username.getText().toString().equals("admin") && password.getText().toString().equals("admin")) {
Intent adminIntent = new Intent(LoginActivity.this, AdminAreaActivity.class);
LoginActivity.this.startActivity(adminIntent);
} else if(username.getText().toString().equals("manager") && password.getText().toString().equals("manager")) {
Intent managerIntent = new Intent(LoginActivity.this, ManagerAreaActivity.class);
LoginActivity.this.startActivity(managerIntent);
}else if(username.getText().toString().equals("user") && password.getText().toString().equals("user")) {
Intent userIntent = new Intent(LoginActivity.this, UserAreaActivity.class);
LoginActivity.this.startActivity(userIntent);
}else {
//wrong password
Toast.makeText(getApplicationContext(), "Wrong Credentials", Toast.LENGTH_SHORT).show();
}
}
});
}
}
Вот мой AdminAreaActivity.java
package online.klok.mobpos;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
public class AdminAreaActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_user_area);
Button bAddUser = (Button) findViewById(R.id.bAddUser);
bAddUser.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
}
});
}
}
Вот мой ManagerAreaActivity.java
package online.klok.mobpos;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
/**
* Created by klok on 1/7/16.
*/
public class ManagerAreaActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_user_area);
final Button bOrderItems = (Button) findViewById(R.id.bOrderItems);
bOrderItems.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
}
});
}
}
Вот мой UserAreaActivity.java
package online.klok.mobpos;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
/**
* Created by klok on 1/7/16.
*/
public class UserAreaActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_user_area);
final Button bSalesReport = (Button) findViewById(R.id.bSalesReport);
bSalesReport.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
}
});
}
}
Избегайте вставки большого блока кода, сделайте его кратким. – David