Consider am having list of items in my android listview.
if i have to change the value on my 3rd item means it's getting the last item value.
What's wrong in my code ? please give me a solution .
i have used belo code in my adapter file :
public View getView(int position, View convertView, ViewGroup parent) {
View vi=convertView;
if(convertView==null) {
vi = inflater.inflate(R.layout.list_profile_griditem, null);
followphotobtn = (Button)vi.findViewById(R.id.followphoto);
HashMap<String, String> Order = new HashMap<String, String>();
Order = data.get(position);
final String photofollowstatus = Order.get(Profile.TAG_PHOTO_FOLLOW_STATUS);
if(photofollowstatus.equalsIgnoreCase("Following")){
followphotobtn.setText("UnFollow");
System.out.println("FollowBtn"+" "+"UnFollow");
}
else {
followphotobtn.setText("Follow");
System.out.println("FollowBtn"+" "+"Follow");
}
it is working well..here am getting the output correctly.
02-03 19:44:57.276: I/System.out(19871): FollowBtn UnFollow
02-03 19:44:57.276: I/System.out(19871): FollowBtn UnFollow
02-03 19:44:57.284: I/System.out(19871): FollowBtn UnFollow
02-03 19:44:57.292: I/System.out(19871): FollowBtn Follow
But i didn't get the correct result in onclicklister :
followphotobtn.setOnClickListener(new View.OnClickListener() {
public void onClick(View arg0) {
if(photofollowstatus.equals("Following")){
new UnFollowPhoto().execute(photo_id);
}
else {
new FollowingPhoto().execute(photo_id);
}
}
});
});
return vi;
}
class FollowingPhoto extends AsyncTask<String, String, String> {
@Override
protected void onPreExecute() {
super.onPreExecute();
//showDialog(DIALOG_LOADING);
}
protected String doInBackground(String... args) {
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://dev.xxx.com/xxx/client/follow.php");
try {
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
System.out.println("photo_id"+" "+args[0]);
nameValuePairs.add(new BasicNameValuePair("userid", LoginPage.userid));
nameValuePairs.add(new BasicNameValuePair("photo_id", args[0]));
nameValuePairs.add(new BasicNameValuePair("photofollow_status", "Following"));
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
response = httpclient.execute(httppost);
HttpEntity entity = response.getEntity();
result_status = EntityUtils.toString(entity);
//res = response.toString();
} catch (ClientProtocolException e) {
} catch (IOException e) {
}
return result_status;
}
protected void onPostExecute(String file_url) {
super.onPostExecute(file_url);
//dismissDialog(DIALOG_LOADING);
Toast.makeText(activity.getApplicationContext(), "Following", Toast.LENGTH_LONG).show();
followphotobtn.setText("UnFollow");
Profile.myphotolistAdapter.notifyDataSetChanged();
followphotobtn.setText("UnFollow");
System.out.println(followphotobtn.getText().toString());
}
}
But i am getting the output is :
02-03 19:45:10.534: I/System.out(19871): UnFollow
But this value is not update in android adapter file while clicking this button..
But i have wrote the code like below means :
protected void onPostExecute(String file_url) {
super.onPostExecute(file_url);
//dismissDialog(DIALOG_LOADING);
Toast.makeText(activity.getApplicationContext(), "Following", Toast.LENGTH_SHORT).show();
followprofilephotobtn.setText("UnFollow");
Intent intent = new Intent(activity,Profile.class);
activity.startActivity(intent);
}
The value is changed once reloaded the activity . But i need to update the value without reload the activity.
What's wrong in my code ? why i have facing this issue ?
Please give me a idea and suggestion ?