我需要通过单击SQLite数据库中列表中的电子邮件来显示数据名称,移动设备和电子邮件。
这是我的听众:
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
email= (String) listView.getItemAtPosition(position);
Intent intent = new
Intent(UserListActivity.this,DisplayActivity.class);
intent.putExtra("Login_Info"," "+email);
startActivity(intent);
}
});
DisplayActivity.java:
public class DisplayActivity extends AppCompatActivity {
ListView listView;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_display);
String login_info = getIntent().getExtras().getString("Login_Info");
DBHelper db = new DBHelper(DisplayActivity.this);
ArrayList<String> displayUsersData = db.displayUsersData(login_info);
ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(DisplayActivity.this,android.R.layout.simple_list_item_1,displayUsersData);
listView = findViewById(R.id.listview_display);
listView.setAdapter(arrayAdapter);
}
这是方法displayUsersData(email):
public ArrayList<String> displayUsersData(String email){
SQLiteDatabase db = getWritableDatabase();
Cursor cursor = db.rawQuery("SELECT * FROM "+TABLE_NAME+" where "+COL_EMAIL+"='"+email+"'",null);
cursor.moveToFirst();
String emailId = cursor.getString(cursor.getColumnIndex(COL_EMAIL));
String name = cursor.getString(cursor.getColumnIndex(COL_NAME));
String mobile = cursor.getString(cursor.getColumnIndex(COL_MOBILE));
ArrayList<String> data = new ArrayList<>();
data.add(emailId);
data.add(name);
data.add(mobile);
return data;
}