gpt4 book ai didi

android - 无法使用 onItemClickListener 获取数据

转载 作者:行者123 更新时间:2023-11-29 02:41:49 24 4
gpt4 key购买 nike

我想 onItemClick ListView 并转到 DetailsPage 以显示详细信息,但它为我提供了空值。ListView 中的项目是图像 url、名称和地址。DetailsPage中的项目是图片url、名称、地址、联系人和类别。

Image of the view on my phone when get null

这是我的 ListViewPage

public class ImageListActivity extends AppCompatActivity {

private DatabaseReference mDatabaseRef;
private List<ImageUpload> imgList;
private ListView lv;
private ImageListAdapter adapter;
private ProgressDialog progressDialog;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_image_list);
imgList = new ArrayList<>();
lv = (ListView) findViewById(R.id.listViewImage);
progressDialog = new ProgressDialog(this);
progressDialog.setMessage("Please wait loading list image...");
progressDialog.show();

mDatabaseRef = FirebaseDatabase.getInstance().getReference(WorkshopsInfoActivity.FB_DATABASE_PATH);

mDatabaseRef.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
progressDialog.dismiss();
for (DataSnapshot snapshot : dataSnapshot.getChildren()) {
ImageUpload img = snapshot.getValue(ImageUpload.class);
imgList.add(img);
}
adapter = new ImageListAdapter(ImageListActivity.this, R.layout.image_item, imgList);
lv.setAdapter(adapter);
}

@Override
public void onCancelled(DatabaseError databaseError) {

progressDialog.dismiss();
}
});
lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
Intent intent = new Intent(getApplicationContext(), DetailsOfWorkshops.class);
startActivity(intent);
}
});
}}

这是我的详情页

public class DetailsOfWorkshops extends AppCompatActivity {

DatabaseReference mDatabaseRef;
List<ImageUpload> listImage;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_details_of_workshops);
mDatabaseRef = FirebaseDatabase.getInstance().getReference(WorkshopsInfoActivity.FB_DATABASE_PATH);
mDatabaseRef.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
ImageUpload img = dataSnapshot.getValue(ImageUpload.class);

String name = img.getName();
String address = img.getAddress();
String contact = img.getContact();
String category = img.getCategory();


final TextView textViewDetails = (TextView) findViewById(R.id.tvName);
String string = "Name: " + name + "\nAddress: " + address + "\nContact: " + contact + "\nCategory: " + category + "\n\n";
textViewDetails.setText(string);
}

@Override
public void onCancelled(DatabaseError databaseError) {

}
});
}}

最佳答案

您没有向详细信息类发送任何内容:

Intent intent = new Intent(getApplicationContext(), DetailsOfWorkshops.class);
startActivity(intent);

尝试使用这个:

YourClass item = (YourClass) adapterView.getAdapter().getItem(position);
Intent intent = new Intent(getApplicationContext().this, DetailsOfWorkshops.class);
Bundle bundle = new Bundle();
bundle.putString("valueName", value);
intent.putExtra("MyPackage", bundle);
startActivity(intent);

关于android - 无法使用 onItemClickListener 获取数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43554326/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com