Hi Dawid, read this tutorial
http://developer.android.com/resources/tutorials/views/hello-listview.html it actually contains the solution for your problem. Best regards, Filip Havlicek 2011/7/1 Dawid Pacholczyk <[email protected]> > 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 > > > -- > Dawid Pacholczyk > tel: 502-054-334 > gg: 5564051 > skype: dpacholczyk > http://typo3blog.pl (only polish version at the moment) > > -- > You received this message because you are subscribed to the Google > Groups "Android Developers" group. > To post to this group, send email to [email protected] > To unsubscribe from this group, send email to > [email protected] > For more options, visit this group at > http://groups.google.com/group/android-developers?hl=en -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/android-developers?hl=en

