在弹出窗口中显示网格视图

时间:2013-02-08 13:10:31

标签: android

我有一个问题,我想在弹出窗口中显示带有图像和文本的自定义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;
    }
}

提前致谢。

1 个答案:

答案 0 :(得分:0)

我找到了解决方案,我正在为弹出窗口两次充气。在显示项目时,我再次给视图充气,然后它没有反映在屏幕上。

使用相同的膨胀视图显示弹出窗口及其包含的项目。

感谢。