OnClickListener in my ListView

by plexus » Wed, 10 Mar 2010 04:35:17 GMT


Sponsored Links
 ow do I add a listner to the list... please show with code

=======
JAVA
=======
public class VelgKomponent extends ListActivity implements
OnClickListener{
String[] listItems = { "exploring", "android", "list", "activities",
"1",
"2", "3", "4" };

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.velgkomp);
setListAdapter(new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1,
listItems));
getListView().setTextFilterEnabled(true);
//
findViewById(android.R.layout.simple_list_item_1).setOnClickListener(this);

Button bTilbake = (Button) findViewById(R.id.bTilbake);
bTilbake.setOnClickListener(this);
}

@Override
public void onClick(View v) {
Intent intent = new Intent(v.getContext(),
ShoppingBasket.class);
startActivity(intent);
}
}

========
XML
========
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/
android"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout android:id="@+id/LinearLayout01"
android:layout_height="wrap_content"
android:layout_width="fill_parent">
<Button android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Tilbake"
android:id="@+id/bTilbake"></Button>
<TextView android:id="@+id/TextView01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Velg komposisjon"
android:gravity="center"></
TextView>
<Button android:id="@+id/Button02"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Endre"></Button>
</LinearLayout>
<LinearLayout android:id="@+id/LinearLayout03"
android:layout_weight="1" android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ListView android:id="@android:id/list"
android:layout_width="fill_parent"
android:layout_weight="1"
android:layout_height="fill_parent"></
ListView>
</LinearLayout>
<LinearLayout android:id="@+id/LinearLayout02"
android:layout_height="wrap_content"
android:layout_width="fill_parent">
<TextView android:text="Dette er en test "
android:layout_width=



OnClickListener in my ListView

by SREEHARI » Wed, 10 Mar 2010 16:52:27 GMT


 Use onListItemClick(ListView list, View view,int position, long id)

REgards,

SREEHARI

--


Sponsored Links


Other Threads

1. Installation unsuccessful - Package file was not signed correctly

I tried to install my application from the market once and got that error,
then I completely removed the previous version I had and installed again
from the market, it installed fine but for some really strange reason it
wasn't able to connect to Internet.

I removed the app from my phone again and installed the unsigned one from
Eclipse and it worked fine. At the beginning I thought that the version I
released was broken in some way but I didn't get any complain about not
being able to connect. So I think it was caused by using different
signatures.


Ivan Soto Fernandez
Web Developer
http://ivansotof.com



2009/4/28 myth2loki <myth2l...@163.com>




--~--~---------~--~----~------------~-------~--~----~

2. Eclipse + cupcake + referenced projects in build path = VerifyError

I ran into the same problem this morning and was hating myself for
being a compulsive early adopter. :)
Also, the fact that you actually have to create a device before you
can launch anything.

Anyone else figured out what is going on?

Inder


On Tue, Apr 28, 2009 at 8:02 AM, Guillaume Perrot



--~--~---------~--~----~------------~-------~--~----~

3. AutoCompleteTextView in 1.5 SDK

4. How does a RemoteView get drawn

5. sdcard in avd SDK 1.5

6. Hardware Overlay

7. i have a question about android device