你好,我需要在 TextView
确切地说 CardView
和 RelativeLayout
我需要插入 SQLite
数据按 CardView
和 RelativeLayout
的片段,其中包含许多 CardView
所以我需要确定哪种布局或 CardView
的数据所属的循环,以便插入它们。
我需要 CardView
名称,以及 RelativeLayout
名称
所以,你有很多CardViews,每个CardView都有一个封装的TextView,你想方便地从TextViews中访问所有这些卡片视图。
我假设TextView的id为 textview1
和 CardView
是 cardview1
然后要获得对父体ID的访问权 CardView
使用其子女 TextView
:
TextView textView1 = findViewById(R.id.textview1);
int id = ((CardView) textView1.getParent()).getId();
还请注意,你永远不会得到 cardview1
作为一个字符串,因为它在系统中存储为int值。
为了确保得到正确的ID,你可以做一些检查,如
if (((CardView) textView1.getParent()).getId() == R.id.cardview1)
Toast.makeText(this, "Cardview", Toast.LENGTH_SHORT).show();