我在我的应用程序中使用Listview,现在我想添加一个类似按钮。
public void likeButton(View view)
{
new PostComment().execute();
}
PostComment课程
class PostComment extends AsyncTask<String, String, String> {
@Override
protected void onPreExecute() {
super.onPreExecute();
pDialog = new ProgressDialog(MainActivity.this);
pDialog.setMessage("Posting Comment...");
pDialog.setIndeterminate(false);
pDialog.setCancelable(true);
pDialog.show();
}
@Override
protected String doInBackground(String... args) {
// TODO Auto-generated method stub
// Check for success tag
int success;
// Just random dummy data
// I need to get the real values
String user = "44";
String post = "12";
try {
// Building Parameters
ArrayList<NameValuePair> params = new ArrayList<NameValuePair>();
params.add(new BasicNameValuePair("user_id", user));
params.add(new BasicNameValuePair("post_id", post));
Log.d("request!", "starting");
//Posting user data to script
JSONObject json = jsonParser.makeHttpRequest(
POST_COMMENT_URL, "POST", params);
// full json response
Log.d("Post Comment attempt", json.toString());
// json success element
success = json.getInt(TAG_SUCCESS);
if (success == 1) {
return json.getString(TAG_MESSAGE);
}else{
Log.d("Comment Failure!", json.getString(TAG_MESSAGE));
return json.getString(TAG_MESSAGE);
}
} catch (JSONException e) {
e.printStackTrace();
}
return null;
}
protected void onPostExecute(String file_url) {
// dismiss the dialog once product deleted
pDialog.dismiss();
if (file_url != null){
Toast.makeText(MainActivity.this, file_url, Toast.LENGTH_LONG).show();
}
}
}
到目前为止,虚拟数据被添加到我的mysql数据库中。但不是虚拟数据:
// Just random dummy data
// I need to get the real values here
String user = "44";
String post = "12";
我希望得到特定帖子的真实post_id,点击按钮。目前,我在列表视图中显示post_id,并在帖子中显示textview。但是如何将这个post_id传递给String post =“”;?