2017-08-05 88 views
0

我有以下代碼:的Android的onClick線性佈局

<?xml version="1.0" encoding="utf-8"?>  
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/list_item" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:layout_margin="10dp" 
    android:orientation="horizontal" 
    android:clickable="true" 
    android:onClick="openGithubUrl"> 

    <ImageView 
     android:layout_width="100dp" 
     android:layout_height="100dp" 
     android:src="@mipmap/github_icon"/> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:orientation="vertical"> 

     <TextView 
      android:id="@+id/github_name" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" /> 
     <TextView 
      android:id="@+id/github_url" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" /> 

    </LinearLayout> 


</LinearLayout> 

我要上的LinearLayout(@ + ID /列表項)添加的onclick監聽器。這可能嗎?在onClick被解僱後,我想要獲得孩子Textview @ + id/github_url的內容。

+0

這是在一個ListView或RecyclerView?如果是這樣,你不要在linearlayout元素上設置點擊監聽器 –

+0

是的,它在一個ListView中 –

+0

然後你使用'listView.setOnItemClickListener',點擊適配器項目,沒有在LinearLayout –

回答

0

是的,您可以將onClickListener設置爲線性佈局,在您的用例中, listItem.setOnClickListener()在活動中。