Exemplo n.º 1
0
  @Override
  public View getView(int position, View convertView, ViewGroup parent) {
    // TODO Auto-generated method stub
    View v;
    Handler handler = new Handler();
    v = convertView;
    LayoutInflater inflater =
        (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    myposition = position;
    System.out.println(
        " book author"
            + bookAuthor.length
            + " book Image"
            + bookImage.length
            + " message"
            + message.length);
    // if (v == null) {
    v = inflater.inflate(R.layout.listview, null);
    handler.book_name = (TextView) v.findViewById(R.id.book_name);
    handler.book_author = (TextView) v.findViewById(R.id.book_author);
    handler.book_image = (ImageView) v.findViewById(R.id.book_image);
    handler.price = (TextView) v.findViewById(R.id.price);
    handler.used_availabel = (TextView) v.findViewById(R.id.used_availabel);
    // if (price[position].equalsIgnoreCase("") || price[position] ==
    // null) {
    v.setTag(handler);

    // }
    try {
      // handler.used_availabel.setVisibility(View.VISIBLE);
      handler.book_author.setText(bookAuthor[position]);
      Log.e("Heell", bookAuthor[position]);
      if (position == 11) {
        position = position - 1;
      }
      handler.book_name.setText(message[position]);
      Log.e("Heell", message[position]);
      Thread t =
          new Thread(
              new Runnable() {

                @Override
                public void run() {
                  // TODO Auto-generated method stub

                  HttpURLConnection connection;
                  try {
                    url = new URL(bookImage[myposition]);
                    // count++;
                    connection = (HttpURLConnection) url.openConnection();
                    connection.setDoInput(true);
                    connection.connect();
                    InputStream input = connection.getInputStream();

                    myBitmap = BitmapFactory.decodeStream(input);
                  } catch (IOException e1) {
                    // TODO Auto-generated catch block
                    e1.printStackTrace();
                  } catch (NullPointerException n) {

                  }
                }
              });
      t.start();
      try {
        t.join();
      } catch (InterruptedException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      }
      handler.book_image.setImageBitmap(myBitmap);

      // synchronized (Thread.currentThread()) {
      // try {
      // Thread.currentThread().wait();
      // } catch (InterruptedException e) {
      // // TODO Auto-generated catch block
      // e.printStackTrace();
      // }
      // }

      // handler.book_image.setImageBitmap(myBitmap);

      // HttpURLConnection connection;
      // try {
      // // System.out.println(imageURL);
      // url = new URL(bookImage[count]);
      // count++;
      // connection = (HttpURLConnection) url
      // .openConnection();
      // connection.setDoInput(true);
      // connection.connect();
      // InputStream input = connection.getInputStream();
      //
      // myBitmap = BitmapFactory.decodeStream(input);
      //
      // } catch (IOException e1) {
      // // TODO Auto-generated catch block
      // e1.printStackTrace();
      // }
      //
      //
      //
      //
      // handler.book_image.setImageBitmap(myBitmap);
      //

      Log.d("checking price[posiotn in custom adaper", price[position]);
      handler.price.setText(price[position]);
    } catch (NullPointerException n) {
      handler.price.setText(" $$");
    }
    //
    // if (count == 1) {
    // System.out.println("he is heeeeee");
    //
    // count++;
    // // if(vendorDetails.getUsedAvailabelDetails(context))
    // // {
    // // handler.used_availabel.setVisibility(View.VISIBLE);
    // // }
    // // System.out.println("Heee is bak");
    // // Parse.initialize(context,
    // // "hhvNehUIwK1iY8Bmtt4FnFoHxWwo0dNgwSnqi7iz",
    // // "B9R0dIdKHeRHyPI0YbShuX9Kapd60yURT7H1c26Z");
    // ParseQuery<ParseObject> queryVendors = ParseQuery
    // .getQuery("BetaObject");
    // queryVendors.whereEqualTo(Preferences.SELL_CHECK, "1");
    // System.out.println("He is finding");
    //
    // queryVendors.findInBackground(new FindCallback<ParseObject>() {
    //
    // @Override
    // public void done(List<ParseObject> arg0, ParseException arg1) {
    // // TODO Auto-generated method stub
    // if (arg0.size() > 0) {
    // temp = 0;
    // } else {
    // temp = 1;
    // }
    // System.out.println("He found" + temp);
    //
    // }
    // });
    //
    // }

    // }

    // else {
    // handler = (Handler) v.getTag();
    // }
    return v;
  }