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. Get the time we pressed a button

I have a Button which MotionEvent and when I need to get the
MOTION_DOWN time event
I want to make a test like this
  if  time(MOTION_DOWN)> 2 seconds to something
  else do other thing

Thank you

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

2. Porting HTC Viva or Dual?

Hi there,

Is it a good call to port HTC dual or Viva? They are among the
cheapest PDAs I can get. I just jump to the Android ship and want to
have some fun. What are some first steps to start from?

Thanks,

WQH
--~--~---------~--~----~------------~-------~--~----~
unsubscribe: android-porting+unsubscr...@googlegroups.com
website: 

3. sending image with URL attached to end of image

4. I want to decode image bitmap retrieved from Picture application

5. How do I get the View dimension after the View has been laid out?

6. How do you save the state of an activity on an ActivityUnitTestCase