第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機(jī)立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何獲取火庫列表對象位置?

如何獲取火庫列表對象位置?

肥皂起泡泡 2022-08-17 12:29:10
我正在使用帶有片段的回收器視圖。以下代碼段從 firebase 檢索數(shù)據(jù)。我還在我的 recyclerview 適配器中實(shí)現(xiàn)了 onClickListener(),并希望啟動一個意圖并顯示一個詳細(xì)的配置文件視圖。(onClickListener正在工作,因?yàn)槲铱梢垣@得日志消息)。但是如何使用 intent.putExtra() 傳遞子密鑰或項(xiàng)目 ID,以便我可以使用該子密鑰或 id 啟動新活動并填充數(shù)據(jù)?火力基礎(chǔ)結(jié)構(gòu)片段public class DoctorsFragment extends Fragment {private List<Doctors> list;private DoctorsAdapter adapter;private DatabaseReference databaseReference;private ValueEventListener valueEventListener;private SearchView searchView = null;private SearchView.OnQueryTextListener queryTextListener;/** * Use this factory method to create a new instance of * this fragment using the provided parameters. * @return A new instance of fragment DoctorsFragment. */// TODO: Rename and change types and number of parameterspublic static DoctorsFragment newInstance() {   return new DoctorsFragment();}@Overridepublic void onCreate(Bundle savedInstanceState) {    super.onCreate(savedInstanceState);    setHasOptionsMenu(true);    getActivity().setTitle(R.string.nav_menu_doctors);}@Overridepublic View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container,                         Bundle savedInstanceState) {    View view = inflater.inflate(R.layout.blank_fragment, container, false);    databaseReference = FirebaseDatabase.getInstance().getReference();    list = new ArrayList<>();    RecyclerView recyclerView = (RecyclerView) view.findViewById(R.id.recycler_view);    adapter = new DoctorsAdapter(getContext(), list);    RecyclerView.LayoutManager layoutManager = new GridLayoutManager(getContext(), 2);    recyclerView.setLayoutManager(layoutManager);    recyclerView.addItemDecoration(new GridSpacingItemDecoration(2, dpToPixel(10), true));    recyclerView.setItemAnimator(new DefaultItemAnimator());    recyclerView.setAdapter(adapter);    adapter.setmOnItemClickListener(onItemClickListener);    asynctask();    return view;}
查看完整描述

1 回答

?
慕慕森

TA貢獻(xiàn)1856條經(jīng)驗(yàn) 獲得超17個贊

在您的醫(yī)生POJO中再添加一個屬性,這將是ID


public class Doctors {


private String id;

private String name;

private String degree;

...

并更新您的構(gòu)造函數(shù)(同時放置您的 setter 和 getter for id)


public Doctors(String id,String name, String specialty, String thumbnail) {

    this.name = name;

    this.specialty = specialty;

    this.thumbnail = thumbnail;

    this.id = id;

}

現(xiàn)在,當(dāng)您獲取數(shù)據(jù)時,獲取檢索到的數(shù)據(jù)的密鑰,這將是您的醫(yī)生ID


valueEventListener = new ValueEventListener() {

        @Override

        public void onDataChange(DataSnapshot dataSnapshot) {

            for (DataSnapshot snapshot: dataSnapshot.getChildren()) {

                String name = snapshot.child("name").getValue(String.class);

                String specialty = snapshot.child("specialty").getValue(String.class);

                String thumbnail = snapshot.child("thumbnail").getValue(String.class);

                String id = snapshot.getKey();

                Doctors doctor = new Doctors(id,name, specialty,thumbnail);

                list.add(doctor);

                adapter.notifyDataSetChanged();

            }

        }

然后在您的通過中,您的意圖中ID的額外內(nèi)容onClickListener()


private View.OnClickListener onItemClickListener = new View.OnClickListener() {

    @Override

    public void onClick(View view) {

        RecyclerView.ViewHolder viewHolder = (RecyclerView.ViewHolder) view.getTag();

        int position = viewHolder.getAdapterPosition();

        Doctors doctor = list.get(position);

        Intent intent = new Intent(getActivity(), DoctorProfile.class);

        intent.putExtra("id",doctor.getID();

        startActivity(intent);


    }

  };


查看完整回答
反對 回復(fù) 2022-08-17
  • 1 回答
  • 0 關(guān)注
  • 120 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號