instantiateItem is calling 3 times and button is not clickable
instantiateItem正在调用3次,并且按钮不可点击
@Override
public Object instantiateItem(ViewGroup container, int position) {
// TODO Auto-generated method stub
inflater1 = (LayoutInflater) context1.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
final View itemView = inflater1.inflate(R.layout.pagerlayout, container,
false);
Log.v("", "CHecking foregroung3");
((ScrollView)itemView. findViewById(R.id.scrollview)).scrollTo(0, 0);
articleTitle_textview = (TextView)itemView.findViewById(R.id.articletitle);
postingTime_textview = (TextView)itemView.findViewById(R.id.postingtime);
articleContent_webview = (WebView)itemView.findViewById(R.id.webview);
csSliderShow=(RelativeLayout)itemView.findViewById(R.id.slide);
countTxt = (TextView)itemView.findViewById(R.id.Count_textView);
previousTxt = (TextView)itemView.findViewById(R.id.prev_textview);
nextText = (TextView)itemView.findViewById(R.id.next_textview);
tab_layout_parent = (RelativeLayout)itemView.findViewById(R.id.tab_layout_parent);
tab_layout = (LinearLayout)itemView.findViewById(R.id.tab_layout);
relatedTxt=(TextView)itemView.findViewById(R.id.related);
relatedArticlesLinearLayoutGridView = (LinearLayout)itemView.findViewById(R.id.linear_related_articles_gridview);
gridView = new ExpandableHeightGridView(ArticleViewActivity.this);
articleContent_webview.invalidate();
//WebView wv = (WebView) findViewById(R.id.webview);
articleContent_webview.getSettings().setBuiltInZoomControls(false);
articleContent_webview.getSettings().setJavaScriptEnabled(true);
try{
/*if (indexofArticle >= 0)
{
if(relatedArticlesLinearLayoutGridView.getChildAt(0) != null)
{
int movement = relatedArticlesLinearLayoutGridView.getChildAt(0).getWidth()* indexofArticle;
//mHoriArticleViewList.scrollTo(movement, 0);
}
}*/
articleTitle_textview.setText(fetchmodel.mTitle);
postingTime_textview.setText(fetchmodel.mPubDate);
String s="<head><style><meta name='viewport' content='target-densityDpi=device-dpi' body{font-size:17px;}/></style></head>";
String addwidth = fetchmodel.mHtmlText;
//Log.v("","Checking Text Before:"+fetchmodel.mHtmlText);
String addwidth1 =addwidth.replace("w=320&q=", "w="+width+"&q=");
articleContent_webview.setWebViewClient(new WebViewClient(){
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
// TODO Auto-generated method stub
Log.v("URL : ", url);
if(url.contains("http:"))
{
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse(url));
startActivity(intent);
return true;
}
return false;
}
@Override
public void onPageFinished(WebView view, String url) {
// TODO Auto-generated method stub
super.onPageFinished(view, url);
}
@Override
public void onPageStarted(WebView view, String url,
Bitmap favicon) {
// TODO Auto-generated method stub
super.onPageStarted(view, url, favicon);
}
});
articleContent_webview.getSettings().setJavaScriptEnabled(true);
articleContent_webview.loadDataWithBaseURL("", s+addwidth1, "text/html", "utf8", "");
//Log.v("","Checking Text After:"+addwidth1);
if(fetchmodel.PhotoFeatureList.size() > 0)
{
csSliderShow.setVisibility(View.VISIBLE);
articleTitle_textview.setVisibility(View.VISIBLE);
postingTime_textview.setVisibility(View.VISIBLE);
csSliderShow.invalidate();
int valuimg=imagNum+1;
countTxt.setText("Slide "+valuimg+" of "+fetchmodel.PhotoFeatureList.size());
String image_url = fetchmodel.PhotoFeatureList.get(imagNum).imgUrl;
String image_url1 = image_url.replace("w=100", "w=300");
csImageLoader.DisplayImage(image_url1, R.drawable.loading, csImageSlider, 0);
titleTxt.setText(fetchmodel.PhotoFeatureList.get(imagNum).subTitle);
headlineTxt.setText(fetchmodel.PhotoFeatureList.get(imagNum).headline);
}
else
{
csSliderShow.setVisibility(View.GONE);
articleTitle_textview.setVisibility(View.GONE);
postingTime_textview.setVisibility(View.GONE);
}
try{
if (fetchmodel.sectionContainerList.size()>0 ) {
Log.v("","CHECKING TABS:");
tab_layout_parent.setVisibility(View.VISIBLE);
tab1 = (Button)itemView.findViewById(R.id.tab1);
tab2 = (Button)itemView.findViewById(R.id.tab2);
tab3 = (Button)itemView.findViewById(R.id.tab3);
imgPoster = (ImageView)itemView.findViewById(R.id.imgPoster0);
TextView profile =(TextView)itemView.findViewById(R.id.profile0);
TextView photos =(TextView)itemView.findViewById(R.id.photos0);
TextView videos =(TextView)itemView.findViewById(R.id.videos0);
countTab = 100;
imgLoader.DisplayImage(fetchmodel.sectionContainerList.get(0).minSectionImgURL, R.drawable.loading, imgPoster, 7);
if (fetchmodel.sectionContainerList.size() == 1) {
tab2.setVisibility(View.GONE);
tab3.setVisibility(View.GONE);
tab1.setText(fetchmodel.sectionContainerList.get(0).minSectionTitle);
imgPoster.setVisibility(View.VISIBLE);
profile.setVisibility(View.VISIBLE);
photos.setVisibility(View.VISIBLE);
videos.setVisibility(View.VISIBLE);
}else if (fetchmodel.sectionContainerList.size() == 2) {
tab3.setVisibility(View.GONE);
tab1.setText(fetchmodel.sectionContainerList.get(0).minSectionTitle);
tab2.setText(fetchmodel.sectionContainerList.get(1).minSectionTitle);
imgPoster.setVisibility(View.VISIBLE);
profile.setVisibility(View.VISIBLE);
photos.setVisibility(View.VISIBLE);
videos.setVisibility(View.VISIBLE);
}else if(fetchmodel.sectionContainerList.size() >= 3){
Log.v("","CHECKING TABS:3");
tab1.setText(fetchmodel.sectionContainerList.get(0).minSectionTitle);
tab2.setText(fetchmodel.sectionContainerList.get(1).minSectionTitle);
tab3.setText(fetchmodel.sectionContainerList.get(2).minSectionTitle);
imgPoster.setVisibility(View.VISIBLE);
profile.setVisibility(View.VISIBLE);
photos.setVisibility(View.VISIBLE);
videos.setVisibility(View.VISIBLE);
imgLoader.DisplayImage(fetchmodel.sectionContainerList.get(0).minSectionImgURL, R.drawable.loading, imgPoster, 7);
}
tab1.setTextColor(Color.RED);
tab2.setTextColor(Color.BLACK);
tab3.setTextColor(Color.BLACK);
tab2.setBackgroundColor(getResources().getColor(R.color.darkgreen));
tab3.setBackgroundColor(Color.GRAY);
tab1.setFocusable(false);
tab2.setFocusable(false);
tab3.setFocusable(false);
tab1.setBackgroundDrawable(null);
tab2.setBackgroundResource(R.drawable.back_button);
tab3.setBackgroundResource(R.drawable.back_button);
tab1.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
try {
tab1.setTextColor(Color.RED);
tab2.setTextColor(Color.BLACK);
tab3.setTextColor(Color.BLACK);
tab2.setBackgroundColor(getResources().getColor(R.color.darkgreen));
tab3.setBackgroundColor(Color.GRAY);
tab1.setBackgroundDrawable(null);
tab2.setBackgroundResource(R.drawable.back_button);
tab3.setBackgroundResource(R.drawable.back_button);
countTab = 100;
imgLoader.DisplayImage(fetchmodel.sectionContainerList.get(0).minSectionImgURL, R.drawable.loading, imgPoster, 7);
} catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
}
}
});
tab2.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
try {
tab1.setTextColor(Color.BLACK);
tab2.setTextColor(Color.RED);
tab3.setTextColor(Color.BLACK);
tab1.setBackgroundColor(Color.GRAY);
tab3.setBackgroundColor(Color.GRAY);
tab2.setBackgroundDrawable(null);
tab1.setBackgroundResource(R.drawable.back_button);
tab3.setBackgroundResource(R.drawable.back_button);
countTab = 200;
imgLoader.DisplayImage(fetchmodel.sectionContainerList.get(1).minSectionImgURL, R.drawable.loading, imgPoster, 7);
} catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
}
}
});
tab3.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
try {
tab1.setTextColor(Color.BLACK);
tab2.setTextColor(Color.BLACK);
tab3.setTextColor(Color.RED);
tab1.setBackgroundColor(Color.GRAY);
tab2.setBackgroundColor(Color.GRAY);
tab3.setBackgroundDrawable(null);
tab2.setBackgroundResource(R.drawable.back_button);
tab1.setBackgroundResource(R.drawable.back_button);
countTab = 300;
imgLoader.DisplayImage(fetchmodel.sectionContainerList.get(2).minSectionImgURL, R.drawable.loading, imgPoster, 7);
} catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
}
}
});
imgPoster.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
try{
if(countTab == 100){
if(fetchmodel.sectionContainerList.get(0).minType.contains("actor")){
Intent intent = new Intent(ArticleViewActivity.this, ActorProfileActivity.class);
intent.putExtra("personID", fetchmodel.sectionContainerList.get(0).minEntryId);
startActivity(intent);
}else if(fetchmodel.sectionContainerList.get(0).minType.contains("movie"))
{
Intent intent = new Intent(ArticleViewActivity.this, MovieProfileActivity.class);
intent.putExtra("movieID", fetchmodel.sectionContainerList.get(0).minEntryId);
startActivity(intent);
}
}else if (countTab == 200) {
if(fetchmodel.sectionContainerList.get(1).minType.contains("actor")){
Intent intent = new Intent(ArticleViewActivity.this, ActorProfileActivity.class);
intent.putExtra("personID", fetchmodel.sectionContainerList.get(1).minEntryId);
startActivity(intent);
}else if(fetchmodel.sectionContainerList.get(1).minType.contains("movie"))
{
Intent intent = new Intent(ArticleViewActivity.this, MovieProfileActivity.class);
intent.putExtra("movieID", fetchmodel.sectionContainerList.get(1).minEntryId);
startActivity(intent);
}
}else if (countTab == 300) {
if(fetchmodel.sectionContainerList.get(2).minType.contains("actor")){
Intent intent = new Intent(ArticleViewActivity.this, ActorProfileActivity.class);
intent.putExtra("personID", fetchmodel.sectionContainerList.get(2).minEntryId);
startActivity(intent);
}else if(fetchmodel.sectionContainerList.get(2).minType.contains("movie"))
{
Intent intent = new Intent(ArticleViewActivity.this, MovieProfileActivity.class);
intent.putExtra("movieID", fetchmodel.sectionContainerList.get(2).minEntryId);
startActivity(intent);
}
}
}catch(Exception e)
{
e.printStackTrace();
}
}
});
profile.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
try{
if(countTab == 100){
if(fetchmodel.sectionContainerList.get(0).minType.contains("actor")){
Intent intent = new Intent(ArticleViewActivity.this, ActorProfileActivity.class);
intent.putExtra("personID", fetchmodel.sectionContainerList.get(0).minEntryId);
startActivity(intent);
}else if(fetchmodel.sectionContainerList.get(0).minType.contains("movie"))
{
Intent intent = new Intent(ArticleViewActivity.this, MovieProfileActivity.class);
intent.putExtra("movieID", fetchmodel.sectionContainerList.get(0).minEntryId);
startActivity(intent);
}
}else if (countTab == 200) {
if(fetchmodel.sectionContainerList.get(1).minType.contains("actor")){
Intent intent = new Intent(ArticleViewActivity.this, ActorProfileActivity.class);
intent.putExtra("personID", fetchmodel.sectionContainerList.get(1).minEntryId);
startActivity(intent);
}else if(fetchmodel.sectionContainerList.get(1).minType.contains("movie"))
{
Intent intent = new Intent(ArticleViewActivity.this, MovieProfileActivity.class);
intent.putExtra("movieID", fetchmodel.sectionContainerList.get(1).minEntryId);
startActivity(intent);
}
}
else if (countTab == 300) {
if(fetchmodel.sectionContainerList.get(2).minType.contains("actor")){
Intent intent = new Intent(ArticleViewActivity.this, ActorProfileActivity.class);
intent.putExtra("personID", fetchmodel.sectionContainerList.get(2).minEntryId);
startActivity(intent);
}else if(fetchmodel.sectionContainerList.get(2).minType.contains("movie"))
{
Intent intent = new Intent(ArticleViewActivity.this, MovieProfileActivity.class);
intent.putExtra("movieID", fetchmodel.sectionContainerList.get(2).minEntryId);
startActivity(intent);
}
}
}catch(Exception e)
{
e.printStackTrace();
}
}
});
photos.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
try{
if(countTab == 100){
if(fetchmodel.sectionContainerList.get(0).minType.contains("actor")){
Intent intent = new Intent(ArticleViewActivity.this, PhotosLandingActitivity.class);
intent.putExtra("photosID", fetchmodel.sectionContainerList.get(0).minEntryId);
intent.putExtra("type", fetchmodel.sectionContainerList.get(0).minType);
intent.putExtra("actions", "FetchPhotos");
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
}else if(fetchmodel.sectionContainerList.get(0).minType.contains("movie"))
{
Intent intent = new Intent(ArticleViewActivity.this, PhotosLandingActitivity.class);
intent.putExtra("photosID", fetchmodel.sectionContainerList.get(0).minEntryId);
intent.putExtra("type", fetchmodel.sectionContainerList.get(0).minType);
intent.putExtra("actions", "FetchPhotos");
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
}
}else if (countTab == 200) {
if(fetchmodel.sectionContainerList.get(1).minType.contains("actor")){
Intent intent = new Intent(ArticleViewActivity.this, PhotosLandingActitivity.class);
intent.putExtra("photosID", fetchmodel.sectionContainerList.get(1).minEntryId);
intent.putExtra("type", fetchmodel.sectionContainerList.get(1).minType);
intent.putExtra("actions", "FetchPhotos");
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
}else if(fetchmodel.sectionContainerList.get(1).minType.contains("movie"))
{
Intent intent = new Intent(ArticleViewActivity.this, PhotosLandingActitivity.class);
intent.putExtra("photosID", fetchmodel.sectionContainerList.get(1).minEntryId);
intent.putExtra("type", fetchmodel.sectionContainerList.get(1).minType);
intent.putExtra("actions", "FetchPhotos");
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
}
}
else if (countTab == 300) {
if(fetchmodel.sectionContainerList.get(2).minType.contains("actor")){
Intent intent = new Intent(ArticleViewActivity.this, PhotosLandingActitivity.class);
intent.putExtra("photosID", fetchmodel.sectionContainerList.get(2).minEntryId);
intent.putExtra("type", fetchmodel.sectionContainerList.get(2).minType);
intent.putExtra("actions", "FetchPhotos");
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
}else if(fetchmodel.sectionContainerList.get(2).minType.contains("movie"))
{
Intent intent = new Intent(ArticleViewActivity.this, PhotosLandingActitivity.class);
intent.putExtra("photosID", fetchmodel.sectionContainerList.get(2).minEntryId);
intent.putExtra("type", fetchmodel.sectionContainerList.get(2).minType);
intent.putExtra("actions", "FetchPhotos");
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
}
}
}catch(Exception e)
{
e.printStackTrace();
}
}
});
videos.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
try{
if(countTab == 100){
if(fetchmodel.sectionContainerList.get(0).minType.contains("actor")){
Intent intent = new Intent(ArticleViewActivity.this, LatestPhotosActivity.class);
intent.putExtra("videoID", fetchmodel.sectionContainerList.get(0).minEntryId);
intent.putExtra("whichscreen", 200);
intent.putExtra("type", "actor");
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
}else if(fetchmodel.sectionContainerList.get(0).minType.contains("movie"))
{
Intent intent = new Intent(ArticleViewActivity.this, LatestPhotosActivity.class);
intent.putExtra("videoID", fetchmodel.sectionContainerList.get(0).minEntryId);
intent.putExtra("whichscreen", 200);
intent.putExtra("type", "movie");
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
}
}else if (countTab == 200) {
if(fetchmodel.sectionContainerList.get(1).minType.contains("actor")){
Intent intent = new Intent(ArticleViewActivity.this, LatestPhotosActivity.class);
intent.putExtra("videoID", fetchmodel.sectionContainerList.get(1).minEntryId);
intent.putExtra("whichscreen", 200);
intent.putExtra("type", "actor");
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
}else if(fetchmodel.sectionContainerList.get(1).minType.contains("movie"))
{
Intent intent = new Intent(ArticleViewActivity.this, LatestPhotosActivity.class);
intent.putExtra("videoID", fetchmodel.sectionContainerList.get(1).minEntryId);
intent.putExtra("whichscreen", 200);
intent.putExtra("type", "movie");
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
}
}else if (countTab == 300) {
if(fetchmodel.sectionContainerList.get(2).minType.contains("actor")){
Intent intent = new Intent(ArticleViewActivity.this, LatestPhotosActivity.class);
intent.putExtra("videoID", fetchmodel.sectionContainerList.get(2).minEntryId);
intent.putExtra("whichscreen", 200);
intent.putExtra("type", "actor");
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
}else if(fetchmodel.sectionContainerList.get(2).minType.contains("movie"))
{
Intent intent = new Intent(ArticleViewActivity.this, LatestPhotosActivity.class);
intent.putExtra("videoID", fetchmodel.sectionContainerList.get(2).minEntryId);
intent.putExtra("whichscreen", 200);
intent.putExtra("type", "movie");
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
}
}
}catch(Exception e)
{
e.printStackTrace();
}
}
});
}
}catch(Exception e)
{
e.printStackTrace();
}
if(relatedArticlesLinearLayoutGridView != null && relatedArticlesLinearLayoutGridView.getChildCount() > 0)
{
relatedArticlesLinearLayoutGridView.removeAllViews();
relatedArticlesLinearLayoutGridView = (LinearLayout)findViewById(R.id.linear_related_articles_gridview);
}
gridView.setNumColumns(2);
gridView.setAdapter(new LazyAdapterForRelatedArticles(mContext,fetchmodel.reLatedArticlesList));
gridView.setExpanded(true);
if(fetchmodel.reLatedArticlesList.size() > 0)
{
Log.v("","checking related:");
relatedTxt.setVisibility(View.VISIBLE);
relatedArticlesLinearLayoutGridView.setVisibility(View.VISIBLE);
}
else
{
relatedTxt.setVisibility(View.GONE);
relatedArticlesLinearLayoutGridView.setVisibility(View.GONE);
}
relatedArticlesLinearLayoutGridView.addView(gridView);
previousTxt.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v)
{
try {
imagNum--;
if(imagNum < 0)
{
imagNum=fetchmodel.PhotoFeatureList.size()-1;
}
int valuimg=imagNum+1;
countTxt.setText("Slide "+valuimg+" of "+fetchmodel.PhotoFeatureList.size());
String image_url = fetchmodel.PhotoFeatureList.get(imagNum).imgUrl;
String image_url1 = image_url.replace("w=100", "w=300");
csImageLoader.DisplayImage(image_url1, R.drawable.loading, csImageSlider, 0);
titleTxt.setText(fetchmodel.PhotoFeatureList.get(imagNum).subTitle);
headlineTxt.setText(fetchmodel.PhotoFeatureList.get(imagNum).headline);
getTracker().trackPageView("ArticleViewPage- Image:"+fetchmodel.PhotoFeatureList.get(imagNum).imgUrl);
} catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
}
}
});
nextText.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v)
{try {
imagNum++;
if(imagNum > fetchmodel.PhotoFeatureList.size()-1)
{
imagNum=0;
}
int valuimg=imagNum+1;
countTxt.setText("Slide "+valuimg+" of "+fetchmodel.PhotoFeatureList.size());
String image_url = fetchmodel.PhotoFeatureList.get(imagNum).imgUrl;
String image_url1 = image_url.replace("w=100", "w=300");
csImageLoader.DisplayImage(image_url1, R.drawable.loading, csImageSlider, 0);
titleTxt.setText(fetchmodel.PhotoFeatureList.get(imagNum).subTitle);
headlineTxt.setText(fetchmodel.PhotoFeatureList.get(imagNum).headline);
getTracker().trackPageView("ArticleViewPage- Image:"+fetchmodel.PhotoFeatureList.get(imagNum).imgUrl);
} catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
}
}
});
gridView.setOnItemClickListener(new OnItemClickListener()
{
@Override
public void onItemClick(AdapterView<?> parent, View view,int position, long id)
{
pageLoadNum = 5050;
strEntryId=csFetchArticle.reLatedArticlesList.get(position).minEntryID;
imagNum=0;
if(csFetchArticle.PhotoFeatureList != null && csFetchArticle.PhotoFeatureList.size() > 0)
{
csFetchArticle.PhotoFeatureList.clear();
}
if(csFetchArticle.reLatedArticlesList != null && csFetchArticle.reLatedArticlesList.size() > 0)
{
csFetchArticle.reLatedArticlesList.clear();
}
articleContent_webview = (WebView)findViewById(R.id.webview);
sendEmptyMessageSync(SHOW_PROGRESS_DIALOG);
sendEmptyMessageAsync(FETCH_ARTICLE);
}
});
}catch(Exception e){
e.printStackTrace();
}
((ViewPager) container).addView(itemView);
//csViePageAdapter.notifyDataSetChanged();
return itemView;
}
@Override
public void destroyItem(ViewGroup container, int position, Object object) {
// Remove viewpager_item.xml from ViewPager
((ViewPager) container).removeView((RelativeLayout) object);
}
}
链接地址: http://www.djcxy.com/p/93386.html