0

だから私は何時間もそこにいて、午前4時7分に今は眠らなければならないので、誰かが私を助けてくれることを願っています。

クラスが次のように定義されているImageResultsオブジェクトのArrayListがあります。

public class ImageResults {

 String _title, _country, _thumbnailURL, _imageURL;

 public ImageResults(String title, String country, String thumbnailURL, String imageURL)
 {
     _title = title;
     _country = country;
     _thumbnailURL = thumbnailURL;
     _imageURL = imageURL;
 }

 public String getTitle()
 {
     return _title;
 }


 public String getCountry()
 {
     return _country;
 }

 public String getThumbnailURL()
 {
     return _thumbnailURL;
 }

 public String getImageURL()
 {
     return _imageURL;
 }
}

https://github.com/thest1/LazyListを使用するには、imageresultsタイプの配列リストからサムネイルURLを取得し、ここで行うように配列に配置する必要があります。

private void populateListBox()
{
    String[] imgLst = new String[imagesList.size()];

    for(int i = 0; i < imagesList.size();i++)
    {
        imgLst[i] = (imagesList.get(i)._thumbnailURL);
    //  Toast t = Toast.makeText(this,imgLst[0] , Toast.LENGTH_SHORT);
    //  t.show();
    }

    adapter=new LazyAdapter(this, imgLst);
    imageListView.setAdapter(adapter);
}

これで、上記の方法は機能しませんが、次のようにリンクを個別に取得すると、元のプロジェクトでリンクが編成されるデフォルトの方法で機能します。

private void populateListBox()
{
     String[] imgLst={
            "http://www.istartedsomething.com/bingimages/resize.php?i=Velodrome_EN-AU1182456710.jpg&w=300"};

    adapter=new LazyAdapter(this, imgLst);
    imageListView.setAdapter(adapter);
}

これは、元のプロジェクトでリンクが編成される方法です。もちろん、両方のメソッドが異なる方法で同じ文字列を返すことを100%確信しています。一方は配列リスト内のオブジェクトから文字列をフェッチし、もう一方は明示的に宣言します。

 private String[] mStrings={
        "http://www.istartedsomething.com/bingimages/resize.php?i=Velodrome_EN-AU1182456710.jpg&w=300",
        "http://www.istartedsomething.com/bingimages/resize.php?i=Velodrome_EN-CA1182456710.jpg&w=300",
        "http://a3.twimg.com/profile_images/121630227/Droid_normal.jpg",
        "http://a1.twimg.com/profile_images/957149154/twitterhalf_normal.jpg",
        "http://a1.twimg.com/profile_images/97470808/icon_normal.png",
        "http://a3.twimg.com/profile_images/511790713/AG.png",
        "http://a3.twimg.com/profile_images/956404323/androinica-avatar_normal.png",
        "http://a1.twimg.com/profile_images/909231146/Android_Biz_Man_normal.png",
        "http://a3.twimg.com/profile_images/72774055/AndroidHomme-LOGO_normal.jpg",
        "http://a1.twimg.com/profile_images/349012784/android_logo_small_normal.jpg"};

主な活動クラス

public class BngPaperActivity extends Activity {

ListView imageListView;
Spinner countrySpinner;
String selectedMonth;
String selectedYear;

LazyAdapter adapter;

ProgressDialog progress;

Dialog date;

getResult getRes;

String ResultsString;

ArrayList<String> monthList = new ArrayList<String>();
ArrayList<ImageResults> imagesList = new ArrayList<ImageResults>();
String dateText;

TextView selectedDateView;
static final int MONTHYEARDATESELECTOR_ID = 3;


/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);



    progress =  new ProgressDialog(BngPaperActivity.this);

    monthList.add("January"); monthList.add("February"); monthList.add("March"); monthList.add("April");
    monthList.add("May"); monthList.add("June"); monthList.add("July"); monthList.add("August");
    monthList.add("September"); monthList.add("October"); monthList.add("November"); monthList.add("December");

    imageListView = (ListView) this.findViewById(R.id.imagesListView);
    countrySpinner = (Spinner) this.findViewById(R.id.countrySpinner);
    selectedDateView = (TextView) this.findViewById(R.id.selectedDateView);



    Button monthYearButton = (Button) this.findViewById(R.id.monthyearBTN);
    // set up a listener for when the button is pressed
    monthYearButton.setOnClickListener(new OnClickListener() {
        public void onClick(View arg0) {
            // call the internal showDialog method using the predefined ID

            showDialog(MONTHYEARDATESELECTOR_ID);
        }
    });

}



private DateSlider.OnDateSetListener mMonthYearSetListener =
    new DateSlider.OnDateSetListener() {
        public void onDateSet(DateSlider view, Calendar selectedDate) {
            // update the dateText view with the corresponding date
            dateText = (String.format("%tB %tY", selectedDate, selectedDate));
            selectedDateView.setText(dateText);
            try {

                 selectedMonth = monthList.indexOf(String.format("%tB", selectedDate)) + 1 +"";
                 selectedYear = String.format("%tY", selectedDate);

                 progress.setMessage("Fetching Images... \nPress Back Button To Cancel");
                 progress.setCancelable(true);


                getRes = new getResult(progress,view);
                getRes.execute();

                try {
                    ResultsString = getRes.get();
                } catch (InterruptedException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                } catch (ExecutionException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }

                parseResults(ResultsString);

            } catch (Exception e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }

        }
};

private void parseResults(String result)
{
  Scanner scan = new Scanner(result);

  String current = scan.nextLine();
  String title = "";
  String country = "";
  String thumbURL = "";
  String imageURL = "";


  while(!current.equals("End of file"))
  {
      if(current.equals("Begin Thumb"))
      {
          current = scan.nextLine();
          title = current.substring(current.indexOf(":")+1);

          current = scan.nextLine();
          country = current.substring(current.indexOf(":")+1);

          current = scan.nextLine();
          thumbURL = current.substring(current.indexOf(":")+1);

          imageURL = thumbURL.replace("300", "900");

          current = scan.nextLine();
      }

      if(current.equals("End Thumb"))
      {
          imagesList.add(new ImageResults(title,country,thumbURL,imageURL));
      }

      current = scan.nextLine();
  }

  populateListBox();

}

private void populateListBox()
{

    //this is not working, i would like this one to work

        String[] imgLst = new String[imagesList.size()];

        for(int i = 0; i < imagesList.size();i++)
        {
            imgLst[i] = (imagesList.get(i)._thumbnailURL);
        //  Toast t = Toast.makeText(this,imgLst[0] , Toast.LENGTH_SHORT);
        //  t.show();
        }
    //-----------------------------------


        /* This is working
            String[] imgLst={
                    "http://www.istartedsomething.com/bingimages/resize.php?i=Velodrome_EN-AU1182456710.jpg&w=300"};
         */
    adapter=new LazyAdapter(this, imgLst);
    imageListView.setAdapter(adapter);
}


@Override
protected Dialog onCreateDialog(int id) {
    // this method is called after invoking 'showDialog' for the first time
    // here we initiate the corresponding DateSlideSelector and return the dialog to its caller

    final Calendar c = Calendar.getInstance();

    final Calendar minDate = Calendar.getInstance();
        minDate.set(Calendar.YEAR, 2009);
        minDate.set(Calendar.MONTH, Calendar.JUNE);
    final Calendar maxDate = Calendar.getInstance();
        maxDate.add(Calendar.DATE, 0);


    switch (id) {

    case MONTHYEARDATESELECTOR_ID:
        return new MonthYearDateSlider(this,mMonthYearSetListener,c,minDate,maxDate);

    }
    return null;
}

private class getResult extends AsyncTask<String, String, String> {


    private final HttpClient Client = new DefaultHttpClient();
    private String Content;
    private String Error = null;
    private ProgressDialog progress;
    DateSlider view;

    public getResult(ProgressDialog progress, DateSlider view) 
    {
        this.progress = progress;
        this.view = view;
    }


    protected void onPreExecute() {

        this.view.dismiss();
        this.progress.show();
    }

    @Override
    protected String doInBackground(String... urls) {
        HttpClient httpclient = new DefaultHttpClient(); 
        HttpResponse response; 
        String responseString = null; 
        try { 
            response = httpclient.execute(new HttpGet("http://devleb.com/BngPaper/BngPaperWebService.php?thumbnail=Yes&year="+selectedYear+"&month="+ selectedMonth)); 
            StatusLine statusLine = response.getStatusLine(); 
            if(statusLine.getStatusCode() == HttpStatus.SC_OK){ 
                ByteArrayOutputStream out = new ByteArrayOutputStream(); 
                response.getEntity().writeTo(out); 
                out.close(); 
                responseString = out.toString(); 
            } else{ 
                //Closes the connection. 
                response.getEntity().getContent().close(); 
                throw new IOException(statusLine.getReasonPhrase()); 
            } 
        } catch (ClientProtocolException e) { 
            //TODO Handle problems.. 
        } catch (IOException e) { 
            //TODO Handle problems.. 
        } 
        //Dialog.dismiss();

        progress.dismiss();
        return responseString; 
    }

    protected void onPostExecute(Void unused) {

        this.progress.dismiss();

        if (Error != null) {
            Toast.makeText(BngPaperActivity.this, Error, Toast.LENGTH_LONG).show();
        } 
    }

}
}
4

1 に答える 1

0

以下は動作しませんか?

private void populateListBox()
{

    adapter=new LazyAdapter(this, mStrings);
    imageListView.setAdapter(adapter);
}

lazylist プロジェクトで与えられた例のように。

于 2012-09-10T01:32:08.833 に答える