我想将listview
从数据库分配给选定的用户...假设user1登录时将显示来自database1的listview
,而user2登录则会显示来自database2的listview
......有可能吗?
答案 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
}
}
}