Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to make the TEXTVIEW wrapped in a ScrollView clickable?
    text
    copied!<p>Here is the layout:</p> <pre><code>&lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="wrap_content" android:descendantFocusability="blocksDescendants" android:orientation="horizontal" &gt; &lt;TextView android:id="@+id/column" android:layout_width="85dp" android:layout_height="30dp" android:layout_alignParentLeft="true" android:layout_marginLeft="5dp" android:layout_marginRight="5dp" android:text="@string/column" android:gravity="center" android:textAppearance="?android:attr/textAppearanceMedium" /&gt; &lt;com.example.demohlistview.InterceptScrollContainer android:id="@+id/scroollContainter" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_alignParentRight="true" android:layout_toRightOf="@id/column" android:focusable="false" &gt; &lt;com.example.demohlistview.MyHScrollView android:id="@+id/horizontalScrollView1" android:layout_width="match_parent" android:layout_height="wrap_content" android:scrollbars="none" &gt; &lt;LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal" &gt; &lt;View android:layout_width="0.5dp" android:layout_height="match_parent" android:background="@color/lineColor" android:visibility="visible" android:clickable="true" android:focusableInTouchMode="true" /&gt; &lt;TextView android:id="@+id/column1" android:layout_width="85dp" android:layout_height="30dp" android:layout_marginLeft="5dp" android:layout_marginRight="5dp" android:text="@string/column1" android:gravity="center" android:textAppearance="?android:attr/textAppearanceMedium" /&gt; &lt;View android:layout_width="0.5dp" android:layout_height="match_parent" android:background="@color/lineColor" android:visibility="visible"/&gt; &lt;TextView android:id="@+id/column2" android:layout_width="85dp" android:layout_height="30dp" android:layout_marginLeft="5dp" android:layout_marginRight="5dp" android:text="@string/column2" android:gravity="center" android:textAppearance="?android:attr/textAppearanceMedium" /&gt; &lt;View android:layout_width="0.5dp" android:layout_height="match_parent" android:background="@color/lineColor" android:visibility="visible"/&gt; &lt;TextView android:id="@+id/column3" android:layout_width="85dp" android:layout_height="30dp" android:layout_marginLeft="5dp" android:layout_marginRight="5dp" android:text="@string/column3" android:gravity="center" android:textAppearance="?android:attr/textAppearanceMedium" /&gt; &lt;/LinearLayout&gt; &lt;/com.example.demohlistview.MyHScrollView&gt; &lt;/com.example.demohlistview.InterceptScrollContainer&gt; </code></pre> <p></p> <p>Here is MyHSrollView:</p> <pre><code>public class MyHScrollView extends HorizontalScrollView { ScrollViewObserver mScrollViewObserver = new ScrollViewObserver(); public MyHScrollView(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); // TODO Auto-generated constructor stub } public MyHScrollView(Context context, AttributeSet attrs) { super(context, attrs); // TODO Auto-generated constructor stub } public MyHScrollView(Context context) { super(context); // TODO Auto-generated constructor stub } @Override public boolean onTouchEvent(MotionEvent ev) { Log.i("pdwy","MyHScrollView onTouchEvent"); return super.onTouchEvent(ev); } @Override protected void onScrollChanged(int l, int t, int oldl, int oldt) { if (mScrollViewObserver != null /*&amp;&amp; (l != oldl || t != oldt)*/) { mScrollViewObserver.NotifyOnScrollChanged(l, t, oldl, oldt); } super.onScrollChanged(l, t, oldl, oldt); } public void AddOnScrollChangedListener(OnScrollChangedListener listener) { mScrollViewObserver.AddOnScrollChangedListener(listener); } public void RemoveOnScrollChangedListener(OnScrollChangedListener listener) { mScrollViewObserver.RemoveOnScrollChangedListener(listener); } public static interface OnScrollChangedListener { public void onScrollChanged(int l, int t, int oldl, int oldt); } public static class ScrollViewObserver { List&lt;OnScrollChangedListener&gt; mList; public ScrollViewObserver() { super(); mList = new ArrayList&lt;OnScrollChangedListener&gt;(); } public void AddOnScrollChangedListener(OnScrollChangedListener listener) { mList.add(listener); } public void RemoveOnScrollChangedListener( OnScrollChangedListener listener) { mList.remove(listener); } public void NotifyOnScrollChanged(int l, int t, int oldl, int oldt) { if (mList == null || mList.size() == 0) { return; } for (int i = 0; i &lt; mList.size(); i++) { if (mList.get(i) != null) { mList.get(i).onScrollChanged(l, t, oldl, oldt); } } } } </code></pre> <p>}</p> <p>Here is my <code>MainActivity</code>:</p> <pre><code>public class MainActivity extends Activity{ ListView mListView1; MyAdapter myAdapter; RelativeLayout mHead; LinearLayout main; TextView text1; private static String TAG = "MainActivity"; public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); requestWindowFeature(Window.FEATURE_NO_TITLE); this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); setContentView(R.layout.activity_main); mHead = (RelativeLayout) findViewById(R.id.head); mHead.setBackgroundResource(R.color.listHeadColor); mHead.setOnTouchListener(new ListViewAndHeadViewTouchLinstener()); mListView1 = (ListView) findViewById(R.id.listView1); myAdapter = new MyAdapter(this, R.layout.item); mListView1.setAdapter(myAdapter); mListView1.setOnTouchListener(new OnTouchListener() { @Override public boolean onTouch(View view, MotionEvent motionevent) { Log.e(TAG,"--------setOnTouchListener"); HorizontalScrollView headSrcrollView = (HorizontalScrollView) mHead .findViewById(R.id.horizontalScrollView1); headSrcrollView.onTouchEvent(motionevent); return false; } }); mListView1.setOnItemClickListener(new ListView.OnItemClickListener() { @Override public void onItemClick(AdapterView&lt;?&gt; listView, View view, int position, long arg3) { MyAdapter.ViewHolder holder = (MyAdapter.ViewHolder) view.getTag(); holder.txt1.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub Log.i(TAG, "--------onclick"); } }); Log.e(TAG, "--------setOnItemClickListener"); myAdapter.setSelectedPosition(position); myAdapter.notifyDataSetInvalidated(); } }); } class ListViewAndHeadViewTouchLinstener implements View.OnTouchListener { @Override public boolean onTouch(View arg0, MotionEvent arg1) { HorizontalScrollView headSrcrollView = (HorizontalScrollView) mHead .findViewById(R.id.horizontalScrollView1); headSrcrollView.onTouchEvent(arg1); return false; } } public class MyAdapter extends BaseAdapter { public List&lt;ViewHolder&gt; mHolderList = new ArrayList&lt;ViewHolder&gt;(); int id_row_layout; LayoutInflater mInflater; private int selectedPosition = -1; public MyAdapter(Context context, int id_row_layout) { super(); this.id_row_layout = id_row_layout; this.mInflater = LayoutInflater.from(context); } @Override public int getCount() { // TODO Auto-generated method stub return 250; } @Override public Object getItem(int arg0) { // TODO Auto-generated method stub return null; } @Override public long getItemId(int arg0) { // TODO Auto-generated method stub return 0; } public void setSelectedPosition(int position) { this.selectedPosition = position; } @Override public View getView(int position, View convertView, ViewGroup parentView) { ViewHolder holder = null; if (convertView == null) { synchronized (MainActivity.this) { convertView = mInflater.inflate(id_row_layout, null); holder = new ViewHolder(); MyHScrollView scrollView1 = (MyHScrollView) convertView .findViewById(R.id.horizontalScrollView1); holder.scrollView = scrollView1; holder.txt = (TextView) convertView .findViewById(R.id.column); holder.txt.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Log.i("jacob", "tex.onClick()"); } }); holder.txt1 = (TextView) convertView .findViewById(R.id.column1); holder.txt1.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Log.i("jacob", "tex1111.onClick()!!!"); } }); holder.txt2 = (TextView) convertView .findViewById(R.id.column2); holder.txt3 = (TextView) convertView .findViewById(R.id.column3); MyHScrollView headSrcrollView = (MyHScrollView) mHead .findViewById(R.id.horizontalScrollView1); headSrcrollView .AddOnScrollChangedListener(new OnScrollChangedListenerImp( scrollView1)); convertView.setTag(holder); mHolderList.add(holder); } } else { holder = (ViewHolder) convertView.getTag(); } holder.txt.setText(position + "" + 11); holder.txt1.setText(position + "" + 1); holder.txt2.setText(position + "" + 2); holder.txt3.setText(position + "" + 3); int intervalColor1 = getResources().getColor(R.color.intervalColor1); int intervalColor2 = getResources().getColor(R.color.intervalColor2); int[] colors = { intervalColor1, intervalColor2}; convertView.setBackgroundColor(colors[position % 2]); if (selectedPosition == position) { convertView.setBackgroundColor(Color.GREEN); } return convertView; } class OnScrollChangedListenerImp implements OnScrollChangedListener { MyHScrollView mScrollViewArg; public OnScrollChangedListenerImp(MyHScrollView scrollViewar) { mScrollViewArg = scrollViewar; } @Override public void onScrollChanged(int l, int t, int oldl, int oldt) { mScrollViewArg.smoothScrollTo(l, t); } }; class ViewHolder{ TextView txt; TextView txt1; TextView txt2; TextView txt3; HorizontalScrollView scrollView; } }// end class my </code></pre> <p>}</p> <p>The <code>InterceptScrollContainer</code> goes here:</p> <pre><code>public class InterceptScrollContainer extends LinearLayout { public InterceptScrollContainer(Context context, AttributeSet attrs) { super(context, attrs); // TODO Auto-generated constructor stub } public InterceptScrollContainer(Context context) { super(context); // TODO Auto-generated constructor stub } @Override public boolean onInterceptTouchEvent(MotionEvent ev) { Log.i("pdwy","ScrollContainer onInterceptTouchEvent"); return true; } </code></pre> <p>}</p> <p>What makes me confused is that the textview outside the scrollview is clickable and print tex.onClick() in the logcat, but the holder.tet1 is unclickable and isn't print "tex1111.onClick()!!!"</p> <p>My question is how to make all the TEXTVIEW in my CUSTOM ScrollView clickable? I think the click event is stopped somewhere and not pass on to the target textview</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload