0
我有一個listview
兩行項目:用戶ID和用戶名。當單擊其中一行時,如何從listview
中僅檢索用戶標識?Android - ListView佈局兩行列表項
public class MainActivity extends AppCompatActivity {
private DatabaseReference mUsers;
String getValue = null;
ListView lvUsers = (ListView) findViewById(R.id.lvUsers);
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mUsers = FirebaseDatabase.getInstance.getReference().child(Constants.FIREBASE_USERS);
FirebaseListAdapter<Users> adapter = new FirebaseListAdapter<Users>(
this, Users.class, android.R.layout.two_line_list_item, mUsers
) {
@Override
protected void populateView(View v, Users user, int pos) {
((TextView)v.findViewById(android.R.id.text1)).setText(user.getUserID());
((TextView)v.findViewById(android.R.id.text2)).setText(user.getUsername());
}
};
lvUsers.setAdapter(adapter);
setupListViewMenu();
}
private void setupListViewMenu() {
lvUsers.setOnItemLongClickListener(
new AdapterView.OnItemLongClickListener() {
@Override
public boolean onItemLongClick(AdapterView<?> adapter,
View item, int pos, long id) {
// How to retrieve only User ID from here?
getValue = ((TextView)view).getText().toString();
return true;
}
});
}
}
listview
數據來自於Firebase數據庫。使用for loop
唯一方法檢索?我必須通過二維數組循環?謝謝