android


How to set onItemClick listener with this


I am using this to retreive a list of items and place them in a list. The URL is retrieved also for each item. I am using ListActivity
// Get all td's that are a child of a row - each game has 4 of these
Elements games = doc.select("tr> td.indexList1, tr > td.indexList2");
Elements links = doc.getElementsByTag("a"); // or getElementsByClass("b1");
// Iterator over those elements
ListIterator<Element> postIt = games.listIterator();
while (postIt.hasNext()) {
// ...It
while (postIt.hasNext()) {
// Add the game text to the ArrayList
Element name = postIt.next();
String nameString = name.text();
String platform = postIt.next().text();
Element url = name.select("a").first();
//Here i retreive the url string for each item
String urlString = url.attr("href");
String genre = postIt.next().text();
String releaseDate = postIt.next().text();
gameList.add(new GameRelease(nameString, platform, genre, releaseDate, urlString));
Log.v(TAG, urlString);
}
this.setListAdapter(new GameReleaseAdapter(this, gameList));
}
I created my own ArrayAdapter here...
private class GameReleaseAdapter extends ArrayAdapter<GameRelease> {
private ArrayList<GameRelease> items;
public GameReleaseAdapter(Context context, ArrayList<GameRelease> items) {
// TODO: make a layout for each item which you'd call (for example) itemLayout
super(context, R.layout.item, items);
this.items = items;
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
// TODO: return an item view styled however you want or as shown in the tutorial
View v = convertView;
if (v == null) {
LayoutInflater vi = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
v = vi.inflate(R.layout.row, null);
}
GameRelease o = items.get(position);
TextView tt = (TextView) v.findViewById(R.id.toptext);
TextView bt = (TextView) v.findViewById(R.id.bottomtext);
TextView plat = (TextView)v.findViewById(R.id.platform);
TextView genre = (TextView)v.findViewById(R.id.genre);
tt.setText(o.getName());
bt.setText("RELEASE DATE: " +o.getReleaseDate());
plat.setText("PLATFORM: " + o.getPlatform());
genre.setText("GENRE: " + o.getGenre());
return v;
}
}
}
How could i store the url for each item so when the item is clicked the url is sent with a extra to another activity? How can i set each item to its own url? How can i let android know that this item in the list was clicked and it should be This url for that particular item?
EDIT - Like this? It gives me tons of syntax errors
while (postIt.hasNext()) {
// Add the game text to the ArrayList
Element name = postIt.next();
String nameString = name.text();
String platform = postIt.next().text();
Element url = name.select("a").first();
String urlString = url.attr("href");
String genre = postIt.next().text();
String releaseDate = postIt.next().text();
gameList.add(new GameRelease(nameString, platform, genre, releaseDate, urlString));
Log.v(TAG, urlString);
}
this.setListAdapter(new GameReleaseAdapter(this, gameList));
final GameReleaseAdapter myGameReleaseAdapter =new GameReleaseAdapter(this,gameList);
setOnItemClickListener(new OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
GameRelease selectedGameRelease =myGameReleaseAdapter .getItem(position);
String urlString=selectedGameRelease.getUrlString();
//Make what you like with the url
}
});
}
when you create the GameReleaseAdapter in your Activity, make sure you have a reference to it like
in onCreate
1- read your gameList
2- after reading it, do this line:
final GameReleaseAdapter myGameReleaseAdapter =new GameReleaseAdapter(this,gameList);
3-
getListView.setOnItemClickListener(new OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
GameRelease selectedGameRelease =myGameReleaseAdapter .getItem(position);
String urlString=selectedGameRelease.getUrlString();
//Make what you like with the url
}
});
OnItemClickListener can be found with AdapterView.OnItemClickListener

Related Links

Phonegap 3.3 resolveLocalFileSystemURI Cannot get Android data/data folder
In Android, why do you need the resource qualifier -mdpi if it is already the default?
Converting a String to an Integer in Android
NFC Reader on ANdroid
Two views referencing each other
Android: check if a View inside of ScrollView is visible
Parse html in android app
image is not saving to android device in Sd card
Encrypt SQLite database without increasing app size?
how to create a folder in android External Storage Directory?
Android can not get the layout [duplicate]
Android TextView not updating even while debugging
KNET Integration for android [closed]
Network query returns local datastore pointer
Application closing on back button after viewing wireless setting by Intent.ACTION_WIRELESS_SETTING
Android rename output of library project

Categories

HOME
search
fpga
github-for-windows
ns-3
depth
package
requirements
cakephp-3.4
visual-studio-emulator
missing-data
frontend
extjs4.2
reactive-programming
enthought
github-enterprise
plist
why3
google-form
flatpak
atlassian-stash
firefox-addon
vuejs
articulate-storyline
spring-async
libigl
r-mice
mongoid6
jboss6.x
opentk
shared
angularjs-components
progress-bar
spotipy
sqsh
boost-asio
gitlab-api
record
kodi
hibernate-validator
catch-unit-test
keras-layer
sendbird
hibernate-search
openproject
google-knowledge-graph
dm-script
z-notation
kill
smoothstate.js
drupal-theming
pom.xml
libgphoto2
sonarlint-eclipse
insight
corruption
boxing
cmp
cvxpy
change-tracking
gets
slackware
cubism.js
hadoop-2.7.2
greatest-n-per-group
windows-azure-queues
xdoclet
simevents
udpclient
hadoop-partitioning
realsense
relativelayout
java-money
rewrite
sql-server-data-tools
apache-commons-daemon
alloy-ui
telepat
kubuntu
deform
contrast
iso-prolog
tweenlite
reflector
live555
matrix-inverse
alternate
draw2d-js
android-framework
authlogic
windows-embedded-standard
high-resolution
unit-of-work
scringo
cmmi
abstract-data-type
octal
virtual-pc
argouml
extreme-programming
qi4j
josql
apache-whirr
failing-tests
xui
tmx
mtu
globals
qtabbar
alsb
fault-tolerance
entitykey
business-model
soappy

Resources

Encrypt Message