2017-07-14 11 views
0

私は2つのビューを持っています。画像とサブタイトルスクロールビュー内のリストビューはクリックできません

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="horizontal" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:background="@color/lightgray"> 
    <ScrollView 
    xmlns:tools="http://schemas.android.com/tools" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content"> 
    <TableLayout 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:stretchColumns="1" 
     android:backgroundTint="#ff81d4fa"> 
     <LinearLayout 
      android:orientation="vertical" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:paddingLeft="10dip"> 
     </LinearLayout> 

     <TextView 
      android:id="@+id/Text1" 
      android:text="Demo Item Name" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:textColor="@color/blue" 
      android:textSize="20dip" /> 
     <TextView 
      android:id="@+id/Text2" 
      android:text="Demo Price" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:textSize="14dip" 
      android:textColor="@color/blue" /> 
    </TableLayout> 
    </ScrollView>  
</LinearLayout> 

についてはMyMenuRestaurent.axml

<LinearLayout> 
<ListView> 
</ListView> 
</LinearLayout> 

コード用 1)MyMenuRestaurent.axml 2)ImageAndSubTitle.axml

コードIは、リストビュークリッカブルを持っています。 1つのアイテムをクリックすると、個々のアイテムの詳細が開きます。私はスクロールビュー(クリック)を追加する場合は動作していません。スクロール・ビュー・ブロックが要素をクリックするためです。私はスクロールビューと一緒にアイテムをクリックしたい。

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="horizontal" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:background="@color/lightgray" 
    android:descendantFocusability="blocksDescendants"> 

それが役に立てば幸い:

+0

を、あなたの問題を解決しましたか? –

+0

unfortunatley no! – DevKriya

+0

それでは、何が問題なのですか?あなたがこの問題を解決するのを手助けできるように、それを詳しく教えてください。 –

答えて

0

は、それがどのように見えるかもしれないが、android:descendantFocusability="blocksDescendants"LinearLayoutで追加してみてください。

+0

あなたの解決策は機能しません! – DevKriya

0

カスタムリストビューでは、アダプタが必要で、カスタムビューを渡します。したがって、onClickListenerをアダプタのカスタムビューの親レイアウトに配置すると、リストビューのonItemClickListenerが模倣されます。

は、スクロールビューブロックは、要素をクリックするので、これはリストビュー

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
      android:orientation="vertical" 
      android:id="@+id/linearLayout" 
      android:layout_width="match_parent" 
      android:layout_height="120dp" 
      > 

<ImageView 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:id="@+id/list_image" 
    android:src="@drawable/homeopathy" 
    android:scaleType="centerCrop" 
    android:tint="#7b000000" 
    /> 

<TextView 
    android:layout_width="match_parent" 
    android:layout_height="20dp" 
    android:layout_marginTop="-67dp" 
    android:gravity="center" 
    android:textColor="#ffffff" 
    android:textSize="15dp" 
    android:text="This is a sample text" 
    android:id="@+id/title" 
    /> 

    </LinearLayout> 

とアダプタで

public View getView(int position, View convertView, ViewGroup parent) { 

     View vi = inflater.inflate(R.layout.list_row, null); 

    TextView title = (TextView) vi.findViewById(R.id.title); 

    ImageView thumb_image=(ImageView) vi.findViewById(R.id.list_image); 
    list= data.get(position); 

    // Setting all values in listview 
    title.setText(list.getTitle()); 
    imageLoader.DisplayImage(list.getImage()); 

    LinearLayout linLayout = (LinearLayout) vi.findViewById(R.id.linearLayout); 

    linLayout.setOnClickListener(new View.OnClickListener() { 
     @Override 
     public void onClick(View v) { 
      //Do what you want to do 
     } 
    }); 


    return vi; 
} 
+0

デモ?またはサンプルコード? – DevKriya

+0

私は答えを確認してください更新しました。 –

0

ためのカスタムビューでみましょう。私はスクロールビューと一緒にアイテムをクリックしたい。

カスタムListViewを書いて、ScrollViewからタッチイベントを取得するためにそのOnInterceptTouchEventメソッドをオーバーライドすることができます。

このメソッドを実装すると、すべてのタッチスクリーンモーションイベントをインターセプトできます。これにより、あなたの子供たちにディスパッチされたイベントを見て、いつでも現在のジェスチャーの所有権を得ることができます。このような

コード:

public class InnerListview : ListView 
{ 
    ... 

    public override bool OnInterceptTouchEvent(MotionEvent ev) 
    { 
     switch (ev.Action) 
     { 
      case MotionEventActions.Down: 
       setParentScrollAble(false); 
       break; 
      case MotionEventActions.Move: 
       break; 
      case MotionEventActions.Up: 
      case MotionEventActions.Cancel: 
       setParentScrollAble(true); 
       break; 
     } 
     return base.OnInterceptTouchEvent(ev); 
    } 

    private void setParentScrollAble(bool flag) 
    { 
     Parent.RequestDisallowInterceptTouchEvent(!flag); 
    } 
} 

はあなたにこのような.axmlこのListViewを使用します。

<ListViewInScrollView.InnerListview 
    android:id="@+id/lv3" 
    android:layout_width="match_parent" 
    android:layout_height="300dp" 
    android:background="#ffffff" /> 
+0

@DevKriya、あなたの問題を解決しましたか? –

関連する問題