Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sqlite/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 如何从其子TextView获取CardView ID_Android_Sqlite_Textview_Fragment - Fatal编程技术网

Android 如何从其子TextView获取CardView ID

Android 如何从其子TextView获取CardView ID,android,sqlite,textview,fragment,Android,Sqlite,Textview,Fragment,您好,我需要在TextView中识别mParent,确切地说是CardView和RelativeLayout 我需要通过片段的cardwiew和RelativeLayout插入SQLite数据,其中包含许多cardwiew;因此,我需要确定数据属于哪个布局或cardwiew,以便循环插入它们 我需要cardwiewname和RelativeLayoutname因此,您有许多cardwiew,每个cardwiew都有一个包装在TextView中的视图,您希望方便从TextView访问所有这些卡视

您好,我需要在
TextView
中识别mParent,确切地说是
CardView
RelativeLayout

我需要通过片段的
cardwiew
RelativeLayout
插入
SQLite
数据,其中包含许多
cardwiew
;因此,我需要确定数据属于哪个布局或
cardwiew
,以便循环插入它们


我需要
cardwiew
name和
RelativeLayout
name

因此,您有许多cardwiew,每个cardwiew都有一个包装在TextView中的视图,您希望方便从TextView访问所有这些卡视图

我将假定TextView的id为
textview1
,而
CardView
的id为
cardview1

然后,要使用其子级
TextView
访问父级
CardView
的ID,请执行以下操作:

TextView textView1 = findViewById(R.id.textview1);
int id = ((CardView) textView1.getParent()).getId();
还要注意的是,您永远不会将
cardwiew1
作为字符串获取,因为它作为int值存储在系统中

为了确保你得到了正确的身份证,你需要做一些检查,比如

if (((CardView) textView1.getParent()).getId() == R.id.cardview1)
    Toast.makeText(this, "Cardview", Toast.LENGTH_SHORT).show();

你好,墨西哥;有一种方法可以获取父视图布局=getParent().toString,这个结果是:android.widget.RelativeLayout{2371e4d V.E………ID 0,0-0,0#7f0a0133 app:ID/relap1},我需要名称relap1你需要父布局的ID吗?是的,我需要文本视图来自的布局的名称,您可以使用
R.id.xx
从版面中获得它,就像文本视图本身的id一样,对吗?@MexiCano welcome。。您还可以将所有文本视图添加到一个数组中,以便于访问它们..Hi,Zain,java.lang.ClassCastException:android.widget.RelativeLayout不能在..----。。。。。。“TextView textView1=v4.findViewById(R.id.textView5);”。。。。“idcard=((CardView)textView1.getParent()).getId();”…----。。。。cardview位于一个linearlayot@MexiCano你能分享一下你的布局吗啊,但是这里没有相对的布局。。您能否共享xml代码?是的,此示例布局: