I am implementing a "like" system in a ListView. Each list item contains a video, the number of likes, the video's id, and the "like" button.
The video_id displays correctly(different for each video), but no matter which "like" button I click, it always sends the video_id from the first item in the list.
To summarize, it seems that my 'Like' method does not know which button is being pressed, and it's automatically choosing the first one and sending that video_id.
All help appreciated!
When the "like" button is clicked, it calls the Like method:
holder.btnLike.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
new Like().execute();
}
});
Here is the Like method:
class Like extends AsyncTask<String, String, String> {
@Override
protected void onPreExecute() {
super.onPreExecute();
pDialog = new ProgressDialog(ThreadActivity.this);
pDialog.setMessage("Creating Product..");
pDialog.setIndeterminate(false);
pDialog.setCancelable(true);
pDialog.show();
}
Bundle extras = getIntent().getExtras();
protected String doInBackground(String... args) {
String price = fbID;
TextView videoid = (TextView)findViewById(R.id.video_id);
String video_id = videoid.getText().toString();
// Building Parameters
List<NameValuePair> params = new ArrayList<NameValuePair>();
params.add(new BasicNameValuePair("price", price));
params.add(new BasicNameValuePair("description", video_id));
// getting JSON Object
// Note that create product url accepts POST method
JSONObject json = jsonParser.makeHttpRequest(url_add_like,
"POST", params);
// check log cat for response
Log.d("Create Response", json.toString());
// check for success tag
try {
int success = json.getInt(TAG_SUCCESS);
if (success == 1) {
// successfully created product
Intent i = new Intent(getApplicationContext(), ThreadActivity.class);
i.putExtra(TAG_PID, pid);
i.putExtra("EXTRA_FACEBOOK_ID",fbID);
startActivity(i);
// closing this screen
finish();
} else {
// failed to create product
}
} catch (JSONException e) {
e.printStackTrace();
}
return null;
}
/**
* After completing background task Dismiss the progress dialog
* **/
protected void onPostExecute(String file_url) {
// dismiss the dialog once done
pDialog.dismiss();
}
}