Hi everyone.
I have a problem with my custom list. I`ve created my own adapter and
everything works great. I have a nice list.
But no I want to add an OnClickListener so I can click on a row and
actualy do something. I`ve created the listener and added it to the
one item of my row BUT it works only at the second click/touch. On the
first nothing happens. I mean that I need to click 2 times on a item
to get some action

Below my adapter, onclick and row.xml

        @Override
        public View getView(int position, View convertView, ViewGroup
parent) {
                View v = convertView;

                if(v == null) {
                        LayoutInflater vi =
(LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
                        v = vi.inflate(R.layout.row, null);
                }

                News news = this.items.get(position);
                if(news != null) {
                TextView tt = (TextView) v.findViewById(R.id.toptext);
                TextView bt = (TextView)
v.findViewById(R.id.bottomtext);
                if (tt != null) {
                      tt.setText("Name: "+ news.getName());
                      tt.setOnClickListener(new TestOnClick(news));
                          }
                if(bt != null){
                      bt.setText("Status: "+
news.getUrl().toString());
                }
                }

                return v;
        }
    }

    private class TestOnClick implements OnClickListener {
        News news;
        public TestOnClick(News n) {
                this.news = n;
        }
        public void onClick(View v) {
                Log.i("testy", this.news.getName());
        }
    }

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/
android"
    android:layout_width="fill_parent"
    android:layout_height="?android:attr/listPreferredItemHeight"
    android:padding="6dip">
    <ImageView
        android:id="@+id/icon"
        android:layout_width="wrap_content"
        android:layout_height="fill_parent"
        android:layout_marginRight="6dip"
        android:src="@drawable/icon" />
    <LinearLayout
        android:id="@+id/item"
        android:orientation="vertical"
        android:layout_width="0dip"
        android:layout_weight="1"
        android:layout_height="fill_parent">
        <TextView
            android:id="@+id/toptext"
            android:layout_width="fill_parent"
            android:layout_height="0dip"
            android:layout_weight="1"
            android:gravity="center_vertical"
                    android:focusable="true"
                        android:focusableInTouchMode="true"
                        android:clickable="true"
        />
        <TextView
            android:id="@+id/bottomtext"
            android:layout_width="fill_parent"
            android:layout_height="0dip"
            android:layout_weight="1"
            android:gravity="center_vertical"
                    android:focusable="true"
                        android:focusableInTouchMode="true"
                        android:clickable="true"
        />

    </LinearLayout>
</LinearLayout>

Please help

Best regards
Dawid "Fixus" Pacholczyk

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to