Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to realize the function of adding Click events in some areas of item in ListView by Android

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces "Android how to add click events in some areas of ListView". In daily operation, I believe many people have doubts about how to add click events in some areas of ListView in Android. Xiaobian consulted all kinds of materials and sorted out simple and easy-to-use methods of operation. I hope it will be helpful for you to answer the questions of "how to add click events in some areas of ListView in Android". Next, please follow the editor to study!

Requirements such as title: click events are added in some areas of item in Android listview, and listview is displayed in an interface, but the display is divided into two parts, namely, the white background and the blue background. Now you only need to click on the blue background to jump to other interfaces. The solution is as follows:

At first, I wondered if I could add one to the upper layout in the list item layout:

Android:clickable= "false" android:focusable= "false"

It is forbidden to click, but it didn't work after trying. Later, the master reminded me that the adapter I used for this listview was the id in which BaseAdapter can get the lower blue Relativelayout in the adapter, and then add click events to this layout to achieve partial regional response events. It is proved to be very feasible, and the main code posted is as follows:

/ / opening order Adapter public class OrderAdapter extends BaseAdapter {public OrderAdapter (Context myContext) {} public OrderAdapter (OrderFragment orderFragment) {} @ Override public int getCount () {if (dataMap = = null) {return orderVec.length;} return dataMap.size ();} @ 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 (R.layout.activity_order_item, null); initViewHolder (convertView, viewHolder, position); / / key code to get the lower blue layout id} else {viewHolder = (ViewHolder) convertView.getTag ();} refreshViewHolder (position, viewHolder); return convertView;} private void refreshViewHolder (int position, ViewHolder viewHolder) {/ /. } private void initViewHolder (View convertView, ViewHolder viewHolder, final int position) {viewHolder.modeifyorder = (RelativeLayout) convertView .findViewById (R.id.modeifyorder); viewHolder.modeifyorder.setOnClickListener (new OnClickListener () {@ Override public void onClick (View v) {Map map = dataMap.get (position); long orderId = Long.parseLong (map.get (Orderid). ToString ()); String instStr = map.get (Instrument). ToString () DocCaptain.getInstance (). SetOrderTrade2Modify (instStr, orderId); getSelfActivity (). ShowOrHideOrderTradeFragment ();}}); convertView.setTag (viewHolder);} private class ViewHolder {TextView orderid; TextView iFDStopPrice; RelativeLayout modeifyorder;}} so far, the study on "how to add click events in some areas of item in ListView by Android" is over, hoping to solve everyone's doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report