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. Signature matching problem

You have to sign it with the same certificate as the target app, so this
generally means you will need to build the target app with the same cert as
you use to build the instrumentation (or really usually the other way
around, since someone is writing instrumentation for their own app).






-- 
Dianne Hackborn
Android framework engineer
hack...@android.com

Note: please don't send private questions to me, as I don't have time to
provide private support, and so won't reply to such e-mails.  All such
questions should be posted on public forums, where I and others can see and
answer them.

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

2. 1.6 error with NumericShaper.class?

Hiya,

When I try to open my SDK 1.1 project with Donut, I get an error (pasted
below).  I did a search and cannot find the NumericShaper anywhere in my
code.  As a matter of fact, I cannot even find an import or call to the
java/awt package.  Can I get a clue about how I might solve it?

Thanks and regards,
Beth

[2009-09-17 13:44:14 - Flipper]processing dalvik/system/Zygote.class...
[2009-09-17 13:44:14 - Flipper]processing
java/awt/font/NumericShaper.class...
[2009-09-17 13:44:14 - Flipper]
trouble processing "java/awt/font/NumericShaper.class":
[2009-09-17 13:44:14 - Flipper]
Attempt to include a core VM class in something other than a core library.
It is likely that you have attempted to include the core library from a
desktop
virtual machine into an application, which will most assuredly not work. If
you really intend to build a core library -- which is only appropriate as
part of creating a full virtual machine binary, as opposed to compiling an
application -- then use the "--core-library" option to suppress this error
message. If you go ahead and use "--core-library" but are in fact building
an application, then please be aware that your build will still fail at some
point; you will simply be denied the pleasure of reading this helpful error
message.
[2009-09-17 13:44:14 - Flipper]1 error; aborting
[2009-09-17 13:44:14 - Flipper]Conversion to Dalvik format failed with error
1
[2009-09-17 13:44:14 - Flipper]Refreshing resource folders.
[2009-09-17 13:44:14 - Flipper]Starting incremental Pre Compiler: Checking
resource changes.
[2009-09-17 13:44:14 - Flipper]Manifest min SDK version (2) is lower than
project target API level (4)
[2009-09-17 13:44:14 - Flipper]Nothing to pre compile!

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

3. ActivityNotFoundException on explicit class declared in manifest on G1, emulator OK

4. can my service still be local if I need to be able to access it from an app and a desktop widget?

5. SDK build fails

6. List of ports.

7. Java Model Exception when cleaning project