私はスタッガードグリッドビューを開発するのが初めてです。スタッガード グリッド ビューに問題があります。上から下にスクロールすると、スクロールされます。しかし、再び下から上にグリッド ビューの開始イメージに移動すると、バンクが表示されます。私はそのために短いスクリーンを送ります..ありがとう事前。
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
boolforprogressdialogmyfeed=true;
BugSenseHandler.initAndStartSession(getApplicationContext(), "ab5c30f1 ");
setContentView(R.layout.activity_activitynewstagredgridview);
mystream=(LinearLayout)findViewById(R.id.mystream);
featured=(LinearLayout)findViewById(R.id.featured);
all=(LinearLayout)findViewById(R.id.popular);
search=(ImageView)findViewById(R.id.search);
mystream_text=(TextView)findViewById(R.id.mystream_text);
featured_text=(TextView)findViewById(R.id.featured_text);
popular_text=(TextView)findViewById(R.id.popular_text);
mystream.setBackgroundResource(R.drawable.shape_tab_left);
featured.setBackgroundColor(Color.parseColor("#3a404c"));
all.setBackgroundColor(Color.TRANSPARENT);
mystream_text.setTextColor(Color.parseColor("#BFC9CB"));
featured_text.setTextColor(Color.parseColor("#BFC9CB"));
popular_text.setTextColor(Color.parseColor("#3a404c"));
mystream.setOnClickListener(this);
featured.setOnClickListener(this);
all.setOnClickListener(this);
search.setOnClickListener(this);
ptrstaggredview=(PullToRefreshStaggeredGridView)findViewById(R.id.staggeredGridView1);
ptrstaggredview.setMode(PullToRefreshBase.Mode.PULL_FROM_START);
popular_Adapter = new ImageBOStaggredAdapter(getParent(),mystreamList.size(),parent, mystreamList);
LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
footerView = inflater.inflate(R.layout.layout_loading_footer, null);
ptrstaggredview.getRefreshableView().setFooterView(footerView);
ptrstaggredview.setAdapter(popular_Adapter);
strcurrenttab="all";
new Load(intstartValue).execute();
popular_Adapter.notifyDataSetChanged();
ptrstaggredview.setOnLoadmoreListener(new StaggeredGridView.OnLoadmoreListener() {
@Override
public void onLoadmore() {
//ptrstaggredview.SMOOTH_SCROLL_LONG_DURATION_MS=BIND_ADJUST_WITH_ACTIVITY;
//dialog=MyProgressDialog.show(getParent(),null,null);
intstartValue=intstartValue+10;
new Load(intstartValue).execute();
//
}
});
/*ObjectAnimator animator=ObjectAnimator.ofInt(yourHorizontalScrollView, "scrollX",targetXScroll );
animator.start();*/
ptrstaggredview.setOnRefreshListener(new PullToRefreshBase.OnRefreshListener<StaggeredGridView>() {
@Override
public void onRefresh(PullToRefreshBase<StaggeredGridView> refreshView) {
boolpulltorefresh=true;
intstartValue=0;
// if(strcurrenttab.equals("mys"))
new Load(intstartValue).execute();
popular_Adapter.notifyDataSetChanged();
ptrstaggredview.onRefreshComplete();
}
});
}
@Override
public void onClick(View v) {
if(v==mystream){
Log.e("onclick for mystream","onclick mystream");
strcurrenttab="mystream"; boolforprogressdialogmyfeed=true;
// ptrstaggredview.removeAllViewsInLayout();
intstartValue=0;
mystream.setBackgroundColor(Color.TRANSPARENT);
featured.setBackgroundColor(Color.parseColor("#3a404c"));
all.setBackgroundResource(R.drawable.shape_tab_right);
mystream_text.setTextColor(Color.parseColor("#3a404c"));
featured_text.setTextColor(Color.parseColor("#BFC9CB"));
popular_text.setTextColor(Color.parseColor("#BFC9CB"));
ptrstaggredview.setMode(PullToRefreshBase.Mode.PULL_FROM_START);
mystreamList.clear();
ImageBOStaggredAdapter.views.clear();
new Load(intstartValue).execute();
popular_Adapter.notifyDataSetChanged();
popular_Adapter = new ImageBOStaggredAdapter(getParent(),mystreamList.size(),parent, mystreamList);
//
//
// LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
// footerView = inflater.inflate(R.layout.layout_loading_footer, null);
// ptrstaggredview.getRefreshableView().setFooterView(footerView);
ptrstaggredview.setAdapter(popular_Adapter);
}else if(v==featured){
Log.e("onclick for featured","onclick featured");
strcurrenttab="featured"; boolforprogressdialogmyfeed=true;
intstartValue=0;
mystream.setBackgroundResource(R.drawable.shape_tab_left);
featured.setBackgroundColor(Color.TRANSPARENT);
all.setBackgroundResource(R.drawable.shape_tab_right);
mystream_text.setTextColor(Color.parseColor("#BFC9CB"));
featured_text.setTextColor(Color.parseColor("#3a404c"));
popular_text.setTextColor(Color.parseColor("#BFC9CB"));
ptrstaggredview.setMode(PullToRefreshBase.Mode.PULL_FROM_START);
mystreamList.clear();
ImageBOStaggredAdapter.views.clear();
new Load(intstartValue).execute();
popular_Adapter.notifyDataSetChanged();
popular_Adapter = new ImageBOStaggredAdapter(getParent(),mystreamList.size(),parent, mystreamList);
//
//
// LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
// footerView = inflater.inflate(R.layout.layout_loading_footer, null);
// ptrstaggredview.getRefreshableView().setFooterView(footerView);
ptrstaggredview.setAdapter(popular_Adapter);
}else if(v==all){
Log.e("onclick for all","onclick all");
strcurrenttab="all"; boolforprogressdialogmyfeed=true;
intstartValue=0;
// ptrstaggredview.removeAllViewsInLayout();
mystream.setBackgroundResource(R.drawable.shape_tab_left);
featured.setBackgroundColor(Color.parseColor("#3a404c"));
all.setBackgroundColor(Color.TRANSPARENT);
mystream_text.setTextColor(Color.parseColor("#BFC9CB"));
featured_text.setTextColor(Color.parseColor("#BFC9CB"));
popular_text.setTextColor(Color.parseColor("#3a404c"));
ptrstaggredview.setMode(PullToRefreshBase.Mode.PULL_FROM_START);
mystreamList.clear();ImageBOStaggredAdapter.views.clear();
new Load(intstartValue).execute();
popular_Adapter.notifyDataSetChanged();
popular_Adapter = new ImageBOStaggredAdapter(getParent(),mystreamList.size(),parent, mystreamList);
//
//
// LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
// footerView = inflater.inflate(R.layout.layout_loading_footer, null);
// ptrstaggredview.getRefreshableView().setFooterView(footerView);
ptrstaggredview.setAdapter(popular_Adapter);
}else if(v==search)
{
// here is the codr for intigrating tabs,..
// Log.e("userrrrrr",""+Logined_User.getId());
View vi =TabActivityActivity.group.getLocalActivityManager()
.startActivity("Items", new Intent(getApplicationContext(),SearchActivity.class)
// .putExtra("imageBo", ""+gson.toJson(imagesBO))
.putExtra("parent", "Activity")
.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP))
.getDecorView();
TabActivityActivity.group.replaceView(vi);
}
}
class Load extends AsyncTask<URL, Integer, Long>
{
/*MyProgressDialog dialog;
JSONObject jobjectsee=null;JSONArray jarray=null;
String jsonresult="";
*/
// Log.e("current before webservice","current time service time"+);
MyProgressDialog dialog;
int strat;
public Load(int strat) {
super();
this.strat = strat;
}
String strjsonresult="";
protected void onPreExecute()
{
if(boolforprogressdialogmyfeed==true){
dialog=MyProgressDialog.show(getParent(), null, null);
dialog.getWindow().setGravity(Gravity.CENTER);
footerView.setVisibility(View.GONE);
// ptrstaggredview.getRefreshableView().re
// ptrstaggredview.h
}else{
footerView.setVisibility(View.VISIBLE);
}
}
@Override
protected Long doInBackground(URL... arg0) {
try {
if(strcurrenttab.equals("mystream")){
Log.e("onpost execute"," on doin of the mystream");
// Log.e("url is...",""+DataUrl.getHomePageByUSer(LogindUser.getUser().getUserId(), strat));
// strjsonresult=Netcon.getValuefromUrl(DataUrl.getHomePageByUSer(LogindUser.getUser().getUserId(), strat));
strjsonresult=Netcon.getValuefromUrl("http://166.78.178.47:8080/json/pinboard?userMystream.userID="+LogindUser.getUser().getUserId()+"&userMystream.start="+strat);
Log.e(" mystream response is ","<><><><<>"+"http://166.78.178.47:8080/json/pinboard?userMystream.userID="+LogindUser.getUser().getUserId()+"&userMystream.start="+strat);
}else if(strcurrenttab.equals("featured"))
{
Log.e("onpost execute"," on do in execut of the featured");
Log.e("url is...",""+DataUrl.getFeaturedImages(strat, LogindUser.getUser().getUserId()));
// featuredList_temp.clear();
strjsonresult=Netcon.getValuefromUrl(DataUrl.getFeaturedImages(strat, LogindUser.getUser().getUserId()));
}else if(strcurrenttab.equals("all"))
{
Log.e("onpost execute"," on doinback execut of the all");
Log.e("url is...",""+DataUrl.getHomePageByCategory(strat, 0, LogindUser.getUser().getUserId()));
// popularList_temp.clear();
strjsonresult=Netcon.getValuefromUrl(DataUrl.getHomePageByCategory(strat, 0, LogindUser.getUser().getUserId()));
}
//this for pulltorefresh
if(boolpulltorefresh==true){
mystreamList.clear();
ImageBOStaggredAdapter.views.clear();
boolpulltorefresh=false;
}
} catch (Exception e1) {
e1.printStackTrace();
}
return null;
}
@SuppressLint("NewApi")
protected void onPostExecute(Long result) {
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
getParent().runOnUiThread(new Runnable() {
@Override
public void run() {
// TODO Auto-generated method stub
//calling();
try {
if(boolforprogressdialogmyfeed==true){
boolforprogressdialogmyfeed=false;
try{
dialog.dismiss();
}catch(Exception e){e.printStackTrace();}
}
if(strcurrenttab.equals("mystream")){
Log.e("onpost execute"," on post execut of the mystream");
/*JSONObject object = new JSONObject(strjsonresult);
if(object.getBoolean("statusFlag"))
{
JSONArray array= object.getJSONArray("homePageImages");
for(int i=0;i<array.length();i++)
{
ImagesBO imagesBO = new ImagesBO();
imagesBO= gson.fromJson(array.getJSONObject(i).toString(), ImagesBO.class);
// mystreamList.add(imagesBO); // commented by Ramesh for endlesscroll
mystreamList.add(imagesBO);
// popular_Adapter.notifyDataSetChanged();
}
}*/
JSONObject jsonObject = new JSONObject(strjsonresult);
JSONArray array = jsonObject.getJSONArray("images");
Log.e("Array size is","<>"+array.length());
for(int i=0;i<array.length();i++)
{
ImagesBO imagesBO = new ImagesBO();
imagesBO= gson.fromJson(array.getJSONObject(i).toString(), ImagesBO.class);
mystreamList.add(imagesBO);
// popularList.add(imagesBO); // added by Ramesh for endlessscroll
// Log.e("userid is","<><>"+imagesBO.getUserId()+imagesBO.getUsername());
}
}else if(strcurrenttab.equals("featured")){
Log.e("onpost execute"," on post execut of the featured");
JSONObject object = new JSONObject(strjsonresult);
JSONArray array= object.getJSONArray("featuredImages");
for(int i=0;i<array.length();i++)
{
ImagesBO imagesBO = new ImagesBO();
imagesBO= gson.fromJson(array.getJSONObject(i).toString(), ImagesBO.class);
// featuredList.add(imagesBO);
mystreamList.add(imagesBO); // added by Ramesh for endlessscroll
// popular_Adapter.notifyDataSetChanged();
}
}else if(strcurrenttab.equals("all")){
Log.e("onpost execute"," on post execut of the all");
JSONObject jsonObject = new JSONObject(strjsonresult);
JSONArray array = jsonObject.getJSONArray("homePageImages");
Log.e("Array size is","<>"+array.length());
for(int i=0;i<array.length();i++)
{
ImagesBO imagesBO = new ImagesBO();
imagesBO= gson.fromJson(array.getJSONObject(i).toString(), ImagesBO.class);
// popularList.add(imagesBO); // added by Ramesh for endlessscroll
mystreamList.add(imagesBO);
// popular_Adapter.notifyDataSetChanged();
// views_popular.add(popularimagelist);
}
}
popular_Adapter.notifyDataSetChanged();
Log.e("Sizeee","<>"+mystreamList.size());
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
//
}
});
// dialog.dismiss();
}
}, 20000);