2013-02-08 68 views
1

我有一個問題,我想在彈出窗口中顯示自定義GridView圖像和文本。圖像來自webservice,但我的適配器無法顯示GridView項目。我不知道爲什麼?請給我建議任何解決方案。在彈出窗口中顯示網格視圖

代碼:

private void showSearchPopUp() 
    { 
     View view = LayoutInflater.from(VideoActivity.this).inflate(R.layout.search_pop_up, null); 
     PopupWindow popupWindow = new PopupWindow(
        view, 
        LayoutParams.WRAP_CONTENT, 
         LayoutParams.WRAP_CONTENT); 
     popupWindow.setWidth(1230); 
     popupWindow.setHeight(800); 
     //popupWindow.showAtLocation(imgSearch, Gravity.LEFT|Gravity.TOP, 0, -30); 
     popupWindow.showAsDropDown(relHeader, 0, -30); 

     LinearLayout llSearchAlpha = (LinearLayout)view.findViewById(R.id.llSearchAlpha); 
     TextView tvAlpha; 
     for(int i=0;i<alpha.length;i++) 
     { 
      tvAlpha = new TextView(VideoActivity.this); 
      tvAlpha.setTextColor(Color.WHITE); 
      tvAlpha.setText(alpha[i]); 
      tvAlpha.setTextSize(15); 
      tvAlpha.setLayoutParams(new LinearLayout.LayoutParams(
         LayoutParams.WRAP_CONTENT, 
         LayoutParams.WRAP_CONTENT, 1f)); 
      llSearchAlpha.addView(tvAlpha); 
     } 
     getActors(); 
    } 

private void getActors() 
    { 
     View view = LayoutInflater.from(VideoActivity.this).inflate(R.layout.search_pop_up, null); 
     final GridView grid = (GridView)view.findViewById(R.id.gvSearch); 
     grid.setWillNotDraw(false); 
     grid.setFocusableInTouchMode(true); 
     grid.setClickable(true); 
     new Thread(new Runnable() { 

      @Override 
      public void run() { 
       actors = Server.getSearchActor(); 
       runOnUiThread(new Runnable() { 

        @Override 
        public void run() { 
         SearchActorCategoryLazyAdapter searchAdapter = new SearchActorCategoryLazyAdapter(VideoActivity.this, actors); 
         grid.setAdapter(searchAdapter); 
        } 
       }); 
      } 
     }).start(); 
    } 

public class SearchActorCategoryLazyAdapter extends BaseAdapter 
{ 
    Context _contextObj; 
    List<Actor> listActor; 
    private LayoutInflater inflater; 
    private ImageLoader imageLoader; 
    public SearchActorCategoryLazyAdapter(Context context, List<Actor> listActor) 
    { 
     _contextObj = context; 
     this.listActor = listActor; 
     this.inflater = (LayoutInflater) _contextObj.getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
     this.imageLoader = new ImageLoader(_contextObj.getApplicationContext()); 
    } 
    @Override 
    public int getCount() 
    { 
     return listActor.size(); 
    } 
    @Override 
    public Object getItem(int position) 
    { 
     return null; 
    } 
    @Override 
    public long getItemId(int position) 
    { 
     return 0; 
    } 

    static class ViewHolder 
    { 
     TextView tvActorName; 
     ImageView imgSearch; 
     int position; 
    } 
    @Override 
    public View getView(int position, View convertView, ViewGroup parent) { 
     ViewHolder viewHolderObj = new ViewHolder(); 

     LayoutInflater inflaterObj = (LayoutInflater)_contextObj.getSystemService(Service.LAYOUT_INFLATER_SERVICE); 


      if (convertView == null) { 
       convertView = (View)inflaterObj.inflate(R.layout.search_griditem, parent,true); 
       } 
      viewHolderObj.tvActorName = (TextView)convertView.findViewById(R.id.tvSearchName); 
      viewHolderObj.imgSearch = (ImageView)convertView.findViewById(R.id.imgSearch); 

      viewHolderObj.tvActorName.setText(listActor.get(position).getActor_name()); 
      Activity activity = (Activity)_contextObj; 
      imageLoader.displayImage(listActor.get(position).getActor_image(), activity, viewHolderObj.imgSearch); 


     return convertView; 
    } 
} 

在此先感謝。

回答

0

我找到了解決方案,我彈出窗口兩次的視圖。在展示物品時,我再次將視圖膨脹,然後它不在屏幕上反射。

使用相同的充氣視圖來顯示彈出窗口及其包含的項目。

謝謝。