m making an application with dynamic listview and viewpager.Whenever user will click on item of listview it will display a viewpager with UpdateDescription and user will be able to swipe page left or right the UpdateDescription will be updated and next data will be displayed..
But i whenever m swiping data same data is getting displayed on each page of viewpager..:( How to update it??
M getting UpdateDescription through UpdateSingleItemViewActivity and m passing it to ViewPagerAdapter to display it in to viewpager....
Here is my code:
UpdateSingleItemViewActivity.java
package com.amlopres.adapter;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.widget.Button;
import com.amlopres.ansari.Cardiology_updates;
import com.amlopres.ansari.R;
public class UpdateSingleItemViewActivity extends Activity {
String UpdateTile;
String UpdateDescription;
String population;
String UpdateImage;
String position;
ViewPager viewPager;
PagerAdapter adapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.activity_update_single_item_view);
Log.e("UpdateSingleItemViewActivity class",
"UpdateSingleItemViewActivity class");
/*
* WebView webview = new WebView(this); setContentView(webview);
*/
Button btnback = (Button) findViewById(R.id.Button01);
btnback.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
finish();
}
});
//WebView webview = (WebView) findViewById(R.id.webview);
Intent i = getIntent();
// Get the result of rank
UpdateTile = i.getStringExtra("UpdateTile");
// Get the result of country
UpdateDescription = i.getStringExtra("UpdateDescription");
// Get the result of population
population = i.getStringExtra("population");
// Get the result of flag
UpdateImage = i.getStringExtra("UpdateImage");
//i.putExtra("POSITION_KEY", position);
//webview.loadData(UpdateDescription, "text/html", null);
viewPager = (ViewPager) findViewById(R.id.viewpager_layout);
// Pass results to ViewPagerAdapter Class
adapter = new ViewPagerAdapter(UpdateSingleItemViewActivity.this, Cardiology_updates.FinalLocalDataList,UpdateDescription);
// Binds the Adapter to the ViewPager
viewPager.setAdapter(adapter);
}
}
ViewPagerAdapter.java:
package com.amlopres.adapter;
import java.util.ArrayList;
import java.util.HashMap;
import com.amlopres.ansari.R;
import com.techvertica.imageloader.ImageLoader;
import android.app.Activity;
import android.content.Context;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.webkit.WebView;
import android.widget.LinearLayout;
public class ViewPagerAdapter extends PagerAdapter {
String UpdateTile;
String UpdateDescription;
//String population;
String UpdateImage;
String position;
LayoutInflater inflater;
Context context;
ArrayList<hashmap><string,>> data;
public ImageLoader imageLoader;
private Activity activity;
HashMap<string,> resultp = new HashMap<string,>();
public ViewPagerAdapter(Context context, ArrayList<hashmap><string,>> arraylist,String UpdateDescription) {
this.context = context;
this.UpdateDescription=UpdateDescription;
data = arraylist;
}
@Override
public int getCount() {
return data.size();
}
/*public Object getItem(int position) {
return data.get(position);
}
*/
@Override
public boolean isViewFromObject(View view, Object object) {
return view == ((LinearLayout) object);
}
@Override
public Object instantiateItem(ViewGroup container, int position) {
WebView webview;
inflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View itemView = inflater.inflate(R.layout.viewpager_item, container,
false);
resultp = data.get(position);
webview=(WebView)itemView.findViewById(R.id.webview1);
//webview.setText(webview[position]);
webview.loadData(UpdateDescription,"text/html", null);
((ViewPager) container).addView(itemView);
return itemView;
}
@Override
public void destroyItem(ViewGroup container, int position, Object object) {
// Remove viewpager_item.xml from ViewPager
((ViewPager) container).removeView((LinearLayout) object);
}
}