<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Hozzászólás: Android onItemClick probléma ListView és Button használatakor</title>
	<atom:link href="http://codeplay.hu/developer/2010/07/android-onitemclick-problema-listview-es-button-hasznalatakor/feed/" rel="self" type="application/rss+xml" />
	<link>http://codeplay.hu/developer/2010/07/android-onitemclick-problema-listview-es-button-hasznalatakor/</link>
	<description>Kitaláljuk, lefejlesztjük, telepítjük</description>
	<lastBuildDate>Tue, 13 Dec 2011 09:56:12 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3</generator>
	<item>
		<title>Szerző: codeplay</title>
		<link>http://codeplay.hu/developer/2010/07/android-onitemclick-problema-listview-es-button-hasznalatakor/comment-page-1/#comment-6431</link>
		<dc:creator>codeplay</dc:creator>
		<pubDate>Tue, 13 Dec 2011 09:56:12 +0000</pubDate>
		<guid isPermaLink="false">http://codeplay.hu/?p=40#comment-6431</guid>
		<description>Thanks, I&#039;m checking. First look I think it isn&#039;t good because &lt;code&gt;ListAdapter.getView()&lt;/code&gt; will run on all list element which is on the screen so &lt;code&gt;v.getId()&lt;/code&gt; will be the id of the last button not what you clicked.
The point there is only one button in the memory and UI redraw it for all list element. You can&#039;t use this button properties only it&#039;s parent.

&lt;code&gt;int myButtonID = v.getId()&lt;/code&gt; will return the last drawn button id not what you clicked.

But I will check...</description>
		<content:encoded><![CDATA[<p>Thanks, I&#8217;m checking. First look I think it isn&#8217;t good because <code>ListAdapter.getView()</code> will run on all list element which is on the screen so <code>v.getId()</code> will be the id of the last button not what you clicked.<br />
The point there is only one button in the memory and UI redraw it for all list element. You can&#8217;t use this button properties only it&#8217;s parent.</p>
<p><code>int myButtonID = v.getId()</code> will return the last drawn button id not what you clicked.</p>
<p>But I will check&#8230;</p>
]]></content:encoded>
	</item>
	<item>
		<title>Szerző: thrash</title>
		<link>http://codeplay.hu/developer/2010/07/android-onitemclick-problema-listview-es-button-hasznalatakor/comment-page-1/#comment-6375</link>
		<dc:creator>thrash</dc:creator>
		<pubDate>Sun, 11 Dec 2011 12:52:57 +0000</pubDate>
		<guid isPermaLink="false">http://codeplay.hu/?p=40#comment-6375</guid>
		<description>There is a much easier way to do the same.
In your ListAdapter getView method:

        Button b = (Button) v.findViewById(R.id.myButton);
        b.setId(item.getEntityValues().getAsInteger(&quot;LIST_ID&quot;));

My list items are Entity.

Define onClick event in your layout xml, and then in the Activity class in the onClick method:

	public void buttonClick(View v) {
		int myButtonID = v.getId();
	}

For me works fine.</description>
		<content:encoded><![CDATA[<p>There is a much easier way to do the same.<br />
In your ListAdapter getView method:</p>
<p>        Button b = (Button) v.findViewById(R.id.myButton);<br />
        b.setId(item.getEntityValues().getAsInteger(&#8220;LIST_ID&#8221;));</p>
<p>My list items are Entity.</p>
<p>Define onClick event in your layout xml, and then in the Activity class in the onClick method:</p>
<p>	public void buttonClick(View v) {<br />
		int myButtonID = v.getId();<br />
	}</p>
<p>For me works fine.</p>
]]></content:encoded>
	</item>
	<item>
		<title>Szerző: Tomasz Prażuch</title>
		<link>http://codeplay.hu/developer/2010/07/android-onitemclick-problema-listview-es-button-hasznalatakor/comment-page-1/#comment-3491</link>
		<dc:creator>Tomasz Prażuch</dc:creator>
		<pubDate>Fri, 05 Aug 2011 10:57:47 +0000</pubDate>
		<guid isPermaLink="false">http://codeplay.hu/?p=40#comment-3491</guid>
		<description>I have had a similar problem: This hint could be useful:
=== part of OnCreate method of the ListActivity class ===

cursor = baza.rawQuery(&quot;SELECT ClientName_id as _id, City, Street, HomeNr, ScanDate, Notes FROM Klienci ORDER BY ClientName_id&quot;,null);
startManagingCursor(cursor);
adapter = new SimpleCursorAdapter(
        		this,
          	    R.layout.list_name,
          	    cursor,
          	    new String[] { &quot;_id&quot;, &quot;City&quot;, &quot;Street&quot;, &quot;HomeNr&quot;, &quot;ScanDate&quot;, &quot;Notes&quot; },
          	    new int[] { R.id.clientname, R.id.city, R.id.street, R.id.homenr, R.id.scanDate, R.id.notes });
this.setListAdapter(adapter);

ListView lv = getListView();
lv.setOnItemClickListener(
    	new OnItemClickListener() {
    		@Override
    		public void onItemClick(AdapterView parent, View view, int position, long id) {
    	        // When clicked, show a toast with the text of a TextView with id &#039;clientname&#039;
    		String txt  = ((TextView)view.findViewById(R.id.clientname)).getText().toString();
    		Toast.makeText(getApplicationContext(), txt, Toast.LENGTH_SHORT).show();
    		}
	});

Rest of the code should be clear. Cheers!</description>
		<content:encoded><![CDATA[<p>I have had a similar problem: This hint could be useful:<br />
=== part of OnCreate method of the ListActivity class ===</p>
<p>cursor = baza.rawQuery(&#8220;SELECT ClientName_id as _id, City, Street, HomeNr, ScanDate, Notes FROM Klienci ORDER BY ClientName_id&#8221;,null);<br />
startManagingCursor(cursor);<br />
adapter = new SimpleCursorAdapter(<br />
        		this,<br />
          	    R.layout.list_name,<br />
          	    cursor,<br />
          	    new String[] { &#8220;_id&#8221;, &#8220;City&#8221;, &#8220;Street&#8221;, &#8220;HomeNr&#8221;, &#8220;ScanDate&#8221;, &#8220;Notes&#8221; },<br />
          	    new int[] { R.id.clientname, R.id.city, R.id.street, R.id.homenr, R.id.scanDate, R.id.notes });<br />
this.setListAdapter(adapter);</p>
<p>ListView lv = getListView();<br />
lv.setOnItemClickListener(<br />
    	new OnItemClickListener() {<br />
    		@Override<br />
    		public void onItemClick(AdapterView parent, View view, int position, long id) {<br />
    	        // When clicked, show a toast with the text of a TextView with id &#8216;clientname&#8217;<br />
    		String txt  = ((TextView)view.findViewById(R.id.clientname)).getText().toString();<br />
    		Toast.makeText(getApplicationContext(), txt, Toast.LENGTH_SHORT).show();<br />
    		}<br />
	});</p>
<p>Rest of the code should be clear. Cheers!</p>
]]></content:encoded>
	</item>
	<item>
		<title>Szerző: Serge</title>
		<link>http://codeplay.hu/developer/2010/07/android-onitemclick-problema-listview-es-button-hasznalatakor/comment-page-1/#comment-3080</link>
		<dc:creator>Serge</dc:creator>
		<pubDate>Thu, 07 Jul 2011 23:37:54 +0000</pubDate>
		<guid isPermaLink="false">http://codeplay.hu/?p=40#comment-3080</guid>
		<description>Hi Guys,

I am having a problem here .
What I want is to have a button on every listview, and also when i click the button it will show a toast containing the writing on that specific view and do the same for every single one of them.
can someone help me please.. 

Thanks</description>
		<content:encoded><![CDATA[<p>Hi Guys,</p>
<p>I am having a problem here .<br />
What I want is to have a button on every listview, and also when i click the button it will show a toast containing the writing on that specific view and do the same for every single one of them.<br />
can someone help me please.. </p>
<p>Thanks</p>
]]></content:encoded>
	</item>
	<item>
		<title>Szerző: ridalm</title>
		<link>http://codeplay.hu/developer/2010/07/android-onitemclick-problema-listview-es-button-hasznalatakor/comment-page-1/#comment-2945</link>
		<dc:creator>ridalm</dc:creator>
		<pubDate>Thu, 23 Jun 2011 18:23:30 +0000</pubDate>
		<guid isPermaLink="false">http://codeplay.hu/?p=40#comment-2945</guid>
		<description>I encountered the same problem recently.
I have solved the problem such that I used the listview position variable as setTag parameter.
Example:

public View getView(int position, View convertView, ViewGroup parent) {
   view.setTag(position);
   view.setOnClickListener(new View.OnClickListener() {
		             public void onClick(View v) {
		            	 String pos=v.getTag().toString();
                                 Toast.makeText(Sehir.this, &quot;clicked &quot;+pos , 0).show();
		              }
		    });

}</description>
		<content:encoded><![CDATA[<p>I encountered the same problem recently.<br />
I have solved the problem such that I used the listview position variable as setTag parameter.<br />
Example:</p>
<p>public View getView(int position, View convertView, ViewGroup parent) {<br />
   view.setTag(position);<br />
   view.setOnClickListener(new View.OnClickListener() {<br />
		             public void onClick(View v) {<br />
		            	 String pos=v.getTag().toString();<br />
                                 Toast.makeText(Sehir.this, &#8220;clicked &#8220;+pos , 0).show();<br />
		              }<br />
		    });</p>
<p>}</p>
]]></content:encoded>
	</item>
	<item>
		<title>Szerző: Don S</title>
		<link>http://codeplay.hu/developer/2010/07/android-onitemclick-problema-listview-es-button-hasznalatakor/comment-page-1/#comment-358</link>
		<dc:creator>Don S</dc:creator>
		<pubDate>Wed, 10 Nov 2010 17:52:27 +0000</pubDate>
		<guid isPermaLink="false">http://codeplay.hu/?p=40#comment-358</guid>
		<description>Thank you very much, this is exactly what I was looking for!</description>
		<content:encoded><![CDATA[<p>Thank you very much, this is exactly what I was looking for!</p>
]]></content:encoded>
	</item>
	<item>
		<title>Szerző: Carl Lee</title>
		<link>http://codeplay.hu/developer/2010/07/android-onitemclick-problema-listview-es-button-hasznalatakor/comment-page-1/#comment-307</link>
		<dc:creator>Carl Lee</dc:creator>
		<pubDate>Sun, 24 Oct 2010 10:50:06 +0000</pubDate>
		<guid isPermaLink="false">http://codeplay.hu/?p=40#comment-307</guid>
		<description>Hey, buddy. I&#039;ve encountered the same problem recently.
Fortunately, I figured out the reason after checking the source code of android.
Because if the one child of ListView returns true when calling its &quot;hasFocusable()&quot; method, Android will ignore the click on the list item. Instead, Android will call the child&#039;s or the child&#039;s child etc. &quot;onClick()&quot; method, in order to make sure &quot;Focusable&quot; objects like Button will work properly.
If you have other problems, send email and let me know~ Peace~</description>
		<content:encoded><![CDATA[<p>Hey, buddy. I&#8217;ve encountered the same problem recently.<br />
Fortunately, I figured out the reason after checking the source code of android.<br />
Because if the one child of ListView returns true when calling its &#8220;hasFocusable()&#8221; method, Android will ignore the click on the list item. Instead, Android will call the child&#8217;s or the child&#8217;s child etc. &#8220;onClick()&#8221; method, in order to make sure &#8220;Focusable&#8221; objects like Button will work properly.<br />
If you have other problems, send email and let me know~ Peace~</p>
]]></content:encoded>
	</item>
</channel>
</rss>

