temClickListener没有响应自定义的ListView

temClickListener没有响应自定义的ListView

本文介绍了setOnItemClickListener没有响应自定义的ListView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写了一个自定义的适配器列表视图,但是当我试图实现单击事件列表项,我发现它是没有回应,我会很高兴,如果有人建议我一个解决方案。

 公共类TourList扩展ListActivity {
....
的setContentView(R.layout.tourlist);
.....





getListView()。setOnItemClickListener(新OnItemClickListener(){
            公共无效onItemClick(适配器视图<>母公司视图中查看,INT位置,长的id){
                     //我不能达到这里
             Log.v(TAG,没有ü得到我);
        }
      });
ADAP =新MyAdapter(TourList.this,mylist中);
getListView()setAdapter(ADAP)。
 

和我的自定义适配器

 私有类MyAdapter扩展了BaseAdapter {

            ArrayList的< HashMap的<字符串,字符串>>元素;
            上下文CTX;

            公共MyAdapter(上下文的背景下,ArrayList的< HashMap的<字符串,字符串>> mylist中){
                  this.elements = mylist中;
                  this.ctx =背景;
             }

            公共布尔的IsEnabled(INT位置){
               返回true;
                      }

            @覆盖
            公众诠释getCount将(){
                返回elements.size();
                }
            @覆盖
            公共对象的getItem(INT位置){
                返回elements.get(位置);
                }
            @覆盖
            众长getItemId(INT位置){
                返回的位置;
                }
                @覆盖
            公共查看getView(INT位置,查看convertView,ViewGroup中父){
                视图V = convertView;
                如果(convertView == NULL){
                      LayoutInflater VI =(LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
                      V = vi.inflate(R.layout.rowfor_tourlist,NULL);
                 }

                    TextView的时间=(TextView中)v.findViewById(R.id.intro);
                    TextView的杜=(TextView中)v.findViewById(R.id.duration);
                    TextView的PF =(TextView中)v.findViewById(R.id.price);
                    TextView的PN =(TextView中)v.findViewById(R.id.product);
                    的WebView WV =(web视图)v.findViewById(R.id.photo);
                    in.setText(Html.fromHtml(mylist.get(位置)获得(简介)));
                    du.setText(mylist.get(位置)获得(持续时间));
                    pf.setText(mylist.get(位置)获得(价格));
                    pn.setText(mylist.get(位置)获得(产品));
                    wv.getSettings()setJavaScriptEnabled(真)。
                    wv.loadUrl(mylist.get(位置)获得(IMAGEURL));

                返回伏;
            }
        }//类
 

和我的tourlist.xml文件看起来像

 <的LinearLayout
        机器人:layout_width =FILL_PARENT
        机器人:layout_height =FILL_PARENT
            ....
        >

 < ListView的机器人:ID =@ ID / Android的:清单
           机器人:layout_width =FILL_PARENT
           机器人:layout_height =FILL_PARENT
           机器人:背景=@可绘制/白
            机器人:cacheColorHint =#00000000
           机器人:layout_weight =1

           />
< /...& GT;
 

解决方案

看看this讨论可以帮助...

I wrote a custom Adapter for a listview ,but when i tried implement click event for list item ,i found that it was not responding ,I will be glad if someone suggest me a solution.

public class TourList extends ListActivity {
....
setContentView(R.layout.tourlist);
.....





getListView().setOnItemClickListener(new OnItemClickListener() {
            public void onItemClick(AdapterView<?> parent, View view,int position, long id) {
                     //i couldn't reach here
             Log.v(TAG,"did u get me");
        }
      });
adap = new MyAdapter(TourList.this,mylist);
getListView().setAdapter(adap);

and my custom adapter is

private class MyAdapter extends BaseAdapter {

            ArrayList<HashMap<String,String>> elements;
            Context ctx;

            public MyAdapter(Context context, ArrayList<HashMap<String,String>> mylist) {
                  this.elements=mylist;
                  this.ctx=context;
             }

            public boolean isEnabled(int position){
               return true;
                      }

            @Override
            public int getCount() {
                return elements.size();
                }
            @Override
            public Object getItem(int position) {
                return elements.get(position);
                }
            @Override
            public long getItemId(int position) {
                return position;
                }
                @Override
            public View getView(int position, View convertView, ViewGroup parent) {
                View v = convertView;
                if (convertView == null) {
                      LayoutInflater vi = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
                      v = vi.inflate(R.layout.rowfor_tourlist, null);
                 }

                    TextView in = (TextView)v.findViewById(R.id.intro);
                    TextView du = (TextView)v.findViewById(R.id.duration);
                    TextView pf = (TextView)v.findViewById(R.id.price);
                    TextView pn = (TextView)v.findViewById(R.id.product);
                    WebView wv=(WebView)v.findViewById(R.id.photo);
                    in.setText(Html.fromHtml(mylist.get(position).get("Intro")));
                    du.setText(mylist.get(position).get("Duration"));
                    pf.setText(mylist.get(position).get("Price"));
                    pn.setText(mylist.get(position).get("Product"));
                    wv.getSettings().setJavaScriptEnabled(true);
                    wv.loadUrl(mylist.get(position).get("ImageURL"));

                return v;
            }
        }//class

and my tourlist.xml file looks like

 <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
            ....
        >

 <ListView android:id="@id/android:list"
           android:layout_width="fill_parent"
           android:layout_height="fill_parent"
           android:background="@drawable/white"
            android:cacheColorHint="#00000000"
           android:layout_weight="1"

           />
</...>
解决方案

See if this discussion helps...

这篇关于setOnItemClickListener没有响应自定义的ListView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-03 00:32