0

I'm new to Java, Android etc. I have a problem that I am not able to figure out.

I have GridView that is populated by an ImageAdapter based on UniversalImageLoader. When I click a button to launch method,

public void buttonsearch(View view)
{
imagesearch();      
}

GridView normally display images. But when I call it directly.

imagesearch("somestring");

It's showing nothing at all. By my "debug" messages I can see that ImageAdapter is working. And when I click the button, the GridView starts filling by content.

private void imagesearch(String... params) throws ClientProtocolException,
        JSONException, IOException, InterruptedException,
        ExecutionException {

    EditText wordimage = (EditText) findViewById(R.id.wordimage);
    String previos = null;
      String wordtotr = null;
        String strwordtos = null;

        if ( params.length != 0 )
          {
          previos = params[0];
          }
        if ( previos != null)
          {
            strwordtos = previos;

            wordimage.setText(strwordtos);
          }
            strwordtos = wordimage.getText().toString().replaceAll(" ", "%20");

    parsejsonimages getUrls = new parsejsonimages();

    getUrls.execute(strwordtos);
    urlsp = getUrls.get();
    List<String> urls = new ArrayList<String>();

    urls = new ArrayList<String>(urlsp.values());
    directurls = new ArrayList<String>(urlsp.keySet());
    int j = 0;

    while (urls.size() > j) {
        urls.set(j, "http://someaddress:" + urls.get(j));
        j++;
    }

    GridView gridview = (GridView) findViewById(R.id.gridViewImages);

    Integer gwight = gridview.getWidth();
    Integer ghight = gridview.getHeight();
    ImageAdapter images = new ImageAdapter(this, urls, ghight, gwight);
    gridview.setAdapter(images);
    gridview.setSelected(true);


    gridview.setOnItemClickListener(new OnItemClickListener() {



        public void setalphatoimagebypos(Integer pos, Integer Alpha)
        {

            GridView gridview = (GridView) findViewById(R.id.gridViewImages);
            ImageView imgrecoil = (ImageView) (gridview
                    .getChildAt(pos));
            imgrecoil.setAlpha(Alpha);

        }

        public void onItemClick(AdapterView parent, View v, int position,
                long id) {

            if (strimgtag > -1) {
                setalphatoimagebypos(strimgtag, 255);           
                strimgtag = position;
                setalphatoimagebypos(strimgtag, 128);


        }

    });

Edit: Ok problem solved explaining will be later

midhunhk
  • 5,560
  • 7
  • 52
  • 83
Rezon
  • 1
  • 2

1 Answers1

0

Ok, so I tried to get the dimensions before GridView was actually drawn. So in OnCreate() when I called this method that will launch my code only after GridView drawn.

public void waiter()
    {
        final GridView gridview1 = (GridView) findViewById(R.id.gridViewImages);

        gridview1.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() 
          {
                @Override
                public void onGlobalLayout() 
                {
                    gridview1.getViewTreeObserver().removeGlobalOnLayoutListener(this);
                    gwight = gridview1.getWidth(); 
                    ghight = gridview1.getHeight();
                        try {
                    imagesearch(wordfromprev);
                    } catch (ClientProtocolException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    } catch (JSONException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    } catch (IOException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    } catch (InterruptedException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    } catch (ExecutionException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }
                }
          });
    }
midhunhk
  • 5,560
  • 7
  • 52
  • 83
Rezon
  • 1
  • 2