[android-developers] onClickListener for on a listView

2010-09-06 Thread kingh32
Hello

I've got some code that pulls pulls in data from a database via a PHP
service layer using JSON etc and displays it as a listview.
It works and I'm very happy with it - but I wanted to add an
onClickListener to it.

I know how to do it for buttons but its proving more difficult for the
list view.

I basically want it to take the ID taken from the JSON and put it into
an intent to another activity.

This is my class...

public class OnlineScores extends Activity
{
/** ListView that holds item references */
ListView li;

/**
 *Array adapter that will hold an ArrayList of invoked items
 *and display these in the ListView
 */
EventAdapter arrayAdapter;
String eventURL;

/** Houses the invoked items */
ArrayListEvent a = new ArrayListEvent();
@Override

/** Called when the activity is first created. */
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.lmain);
Intent intent = this.getIntent();
Bundle b = intent.getExtras();
eventURL = b.getString(URL);

//Initialise ListView
li=(ListView)findViewById(R.id.lstText);
arrayAdapter = new 
EventAdapter(OnlineScores.this,R.layout.list,a);

// Set above adapter for the ArrayList
li.setAdapter(arrayAdapter);

// Create an object of the GetData class
GetData g = new GetData();
String response = g.getIt(,,eventURL);

try
{
// Put JSON response into an object
Type collectionType = new TypeTokenArrayListEvent()
{}.getType();

List Event lst= new Gson().fromJson(response, 
collectionType);

for(Event l : lst)
{
a.add(l);
}
// Inform the ArrayAdapter of the change from ArrayList 
to List
arrayAdapter.notifyDataSetChanged();
}
catch(Exception e)
{

}
}
}

I'm trying to implement this...

lstText.setOnItemClickListener(new AdapterView.OnItemClickListener()
{
 @Override
 public void onItemClick(AdapterView? a, View v, int 
position,
long id)
 {
 // Do stuff here
 }
 });

but I'm being told to remove the @Override statement AND to inherit
abstract methods.

Any ideas?

-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en


Re: [android-developers] onClickListener for on a listView

2010-09-06 Thread TreKing
On Mon, Sep 6, 2010 at 8:30 AM, kingh32 horaceb1...@gmail.com wrote:

 I'm trying to implement this...

 lstText.setOnItemClickListener(new AdapterView.OnItemClickListener()
{
 @Override
 public void onItemClick(AdapterView? a, View v,
 int position,
 long id)
 {
 // Do stuff here
 }
 });

 but I'm being told to remove the @Override statement AND to inherit
 abstract methods.


That seems about right (compared to my code). Is it complaining about the
@Override in teh onItemClick? Which class does it want you to inherit
abstract methods for? And which methods?

-
TreKing http://sites.google.com/site/rezmobileapps/treking - Chicago
transit tracking app for Android-powered devices

-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en