英文:
I got key for every item in the listView and its saved to Firebase I want to send that key to another activity but every time I got the same key
问题
mChildEventListner = new ChildEventListener() {
@Override
public void onChildAdded(@NonNull DataSnapshot dataSnapshot, @Nullable String s) {
AdClass adClass = dataSnapshot.getValue(AdClass.class);
list.add(0, adClass);
listView.setAdapter(adapter);
// here I save the key in a global variable named listId.
listId = dataSnapshot.getKey();
}
};
// - here I send that id via intent to another activity
AdsList.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(getContext(), AdsDescrption.class);
intent.putExtra("resId", listId);
startActivity(intent);
}
});
// - and the problem is I always get the same key
Intent intent = getIntent();
resId = intent.getStringExtra("resId");
英文:
mChildEventListner = new ChildEventListener() {
@Override
public void onChildAdded(@NonNull DataSnapshot dataSnapshot, @Nullable String s) {
AdClass adClass = dataSnapshot.getValue(AdClass.class);
list.add(0,adClass);
listView.setAdapter(adapter);
-
here I save the key in global variable named listId.
listId = dataSnapshot.getKey(); } -here I send that id via intent to another activity AdsList.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent intent = new Intent(getContext(),AdsDescrption.class); intent.putExtra("resId",listId); startActivity(intent); } });
-and the problem I always get the same key
Intent intent = getIntent();
resId =intent.getStringExtra("resId");
答案1
得分: 0
使用
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
//Your code goes here
}
});
英文:
Use
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
//Your code goes here
}
});
专注分享java语言的经验与见解,让所有开发者获益!
评论