This article describes the Android programming implementation of the function of adding click event in some areas of the item in ListView. Share it for your reference, as follows:
As required, the title is: Add a click event in part of the item area in the Android listview. The listview is displayed in one interface, but the content displayed is divided into two parts, namely a white background and a blue background. Now you need to only click on the blue background to jump to other interfaces. The solution is as follows:
At the beginning, I wondered if I could add one to the upper layout in the list item layout:
android:clickable="false" android:focusable="false"
Clicks are prohibited, but the trial has no effect. Later, the master reminded me that the adapter used by my listview is BaseAdapter that can get the blue Relativelayout id in the adapter, and then add a click event to this layout to realize some areas of response events. It turns out that it is very feasible., the main code is posted as follows:
// Warehouse Opening Invoice Adapterpublic class OrderAdapter extends BaseAdapter { public OrderAdapter(Context myContext) { } public OrderAdapter(OrderFragment orderFragment) { } @Override public int getCount() { if (dataMap == null) { return ; } return (); } @Override public Object getItem(int position) { return position; } @Override public long getItemId(int position) { return position; } @Override public View getView(int position, View convertView, ViewGroup parent) { ViewHolder viewHolder = null; if (convertView == null) { viewHolder = new ViewHolder(); convertView = getActivity().getLayoutInflater().inflate( .activity_order_item, null); initViewHolder(convertView, viewHolder, position); //Key code, get the id of the lower blue layout } else { viewHolder = (ViewHolder) (); } refreshViewHolder(position, viewHolder); return convertView; } private void refreshViewHolder(int position, ViewHolder viewHolder) { //。。。。。。。。 } private void initViewHolder(View convertView, ViewHolder viewHolder, final int position) { = (RelativeLayout) convertView .findViewById(); (new OnClickListener() { @Override public void onClick(View v) { Map<String, Object> map = (position); long orderId = ((Orderid).toString()); String instStr = (Instrument).toString(); ().setOrderTrade2Modify(instStr, orderId); getSelfActivity().showOrHideOrderTradeFragment(); } }); (viewHolder); } private class ViewHolder { TextView orderid; TextView iFDStopPrice; RelativeLayout modeifyorder; } }
Completed successfully, record it.
For more information about Android related content, please check out the topic of this site:Android control usage summary》、《Android development introduction and advanced tutorial》、《Android View View Tips Summary》、《Android programming activity operation skills summary》、《Android database operation skills summary"and"Android resource operation skills summary》
I hope this article will be helpful to everyone's Android programming design.