如何在android中向选定用户显示数据?

时间:2018-01-11 02:33:45

标签: android listview firebase

我想将listview从数据库分配给选定的用户...假设user1登录时将显示来自database1的listview,而user2登录则会显示来自database2的listview ......有可能吗?

1 个答案:

答案 0 :(得分:-1)

试试这个:

在LoginActivity中

yourButtonLogin.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
         String username = yourEditTextUsername.getText().toString();
         Intent intent = new Intent(this,YOUR_ACTIVITY.class);
         intent.putExtra("username",username);
         startActivity(intent);
    }
});

在YOUR_ACTIVITY

String username;
@Override
protected void onCreate(Bundle savedInstanceState) {
     super.onCreate(savedInstanceState);
     setContentView(R.layout.YOUR_LAY_OUT);
     Intent intent = getIntent();
     if(intent != null){
         username = intent.getStringExtra("username");
         if(username.equals("user1")){
             //get data from database1 and set data to listview 
         } else if (username.equals("user2")){
             //get data from database2 and set data to listview 
         }
     }
 }