Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/220.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 从异步任务使用通用映像加载程序_Android_Image_Android Asynctask_Loader_Universal - Fatal编程技术网

Android 从异步任务使用通用映像加载程序

Android 从异步任务使用通用映像加载程序,android,image,android-asynctask,loader,universal,Android,Image,Android Asynctask,Loader,Universal,我想从asynctask使用UIL import com.nostra13.universalimageloader.core.DisplayImageOptions; import com.nostra13.universalimageloader.core.ImageLoaderConfiguration; public class SingleAppDetail extends Activity { Button btnLogout;

我想从asynctask使用UIL

    import com.nostra13.universalimageloader.core.DisplayImageOptions;
    import com.nostra13.universalimageloader.core.ImageLoaderConfiguration;

    public class SingleAppDetail extends Activity {
        Button btnLogout;
        Button btShowProgress;
        // Progress Dialog
        private ProgressDialog pDialog;
        JSONparser jParser = new JSONparser();
        // Progress dialog type (0 - for Horizontal progress bar)
        public static final int progress_bar_type = 0;
        private static String file_url = "http://site.com/as.apk";
    JSONArray detalii = null;
    TextView app_Detail_title;
    Button app_price_button;
    TextView app_Description;
    ImageView app_Picture;
    View loadingPanelViev;
    View appDetailHeader;
    RatingBar appDetailRating;
    RatingBar rating_1;
    RatingBar rating_2;
    RatingBar rating_3;
    RatingBar rating_4;
    RatingBar rating_5;
    RatingBar rating_ff;
    TextView rating_ff_text;
    TextView rating_1_text;
    TextView rating_2_text;
    TextView rating_3_text;
    TextView rating_4_text;
    TextView rating_5_text;
    String[] imageUrls;
    ImageSwitcher appGallery;
    DisplayImageOptions options;
    com.nostra13.universalimageloader.core.ImageLoader ImageLoader;
    Gallery app_gallery;
    ArrayList<String> urlse = new ArrayList<String>();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        setContentView(R.layout.app_detail);
        app_Detail_title = (TextView) findViewById(R.id.app_detail_title);
        app_price_button = (Button) findViewById(R.id.app_detail_price);
        app_Description = (TextView) findViewById(R.id.description_holder);
        app_Picture = (ImageView) findViewById(R.id.singleAppDetailImage);
        loadingPanelViev = (View) findViewById(R.id.loadingPanelAppDetailHeader);
        appDetailHeader = (View) findViewById(R.id.app_detail_header_content);
        appDetailRating = (RatingBar) findViewById(R.id.app_detail_rating);
        rating_1 = (RatingBar) findViewById(R.id.rating_1);
        rating_2 = (RatingBar) findViewById(R.id.rating_2);
        rating_3 = (RatingBar) findViewById(R.id.rating_3);
        rating_4 = (RatingBar) findViewById(R.id.rating_4);
        rating_5 = (RatingBar) findViewById(R.id.rating_5);
        rating_ff = (RatingBar) findViewById(R.id.rating_ff);
        rating_ff_text = (TextView) findViewById(R.id.rating_ff_text);
        rating_1_text = (TextView) findViewById(R.id.rating_1_text);
        rating_2_text = (TextView) findViewById(R.id.rating_2_text);
        rating_3_text = (TextView) findViewById(R.id.rating_3_text);
        rating_4_text = (TextView) findViewById(R.id.rating_4_text);
        rating_5_text = (TextView) findViewById(R.id.rating_5_text);
        // appGallery=(ImageSwitcher)findViewById(R.id.app_detail_gallery);
        app_gallery = (Gallery) findViewById(R.id.app_gallery);
        DisplayImageOptions defaultOptions = new DisplayImageOptions.Builder()
                .cacheInMemory().build();

        ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(
                getApplicationContext()).defaultDisplayImageOptions(
                defaultOptions).build();
        ImageLoader.getInstance().init(config);

        new loadAppMainDetails(getApplicationContext()).execute();
        new loadAppMainRating(getApplicationContext()).execute();
        new loadAppMainImages(getApplicationContext()).execute();
        Button download = (Button) findViewById(R.id.app_detail_price);
        download.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub

                new DownloadFileFromURL().execute(file_url);
            }
        });

    }

    /**
     * Showing Dialog
     * */
    @Override
    protected Dialog onCreateDialog(int id) {
        //this is ok
    }

    /**
     * Background Async Task to download file
     * */

    class DownloadFileFromURL extends AsyncTask<String, String, String> {
//this is ok
}



    class loadAppMainDetails extends
            AsyncTask<String, String, HashMap<String, String>> {
//this is ok
}

    class loadAppMainRating extends AsyncTask<String, String, String> { 
this is ok;
}
// here starts the problem
    class loadAppMainImages extends AsyncTask<String, String, String> {
        Context mContext;
        JSONArray appDetailPictures;
        String image_path;
        public loadAppMainImages(Context context) {
            super();
            this.mContext = context;
        }

        @Override
        protected String doInBackground(String... params) {
            Intent is = getIntent();
            String app_id = is.getStringExtra("element_id");
            List<NameValuePair> parameters = new ArrayList<NameValuePair>();
            parameters.add(new BasicNameValuePair("app_id", app_id));
            JSONObject json = jParser.makeHttpRequest(
                    "http://himbimarket.com/masterApp/get_app_pictures.php",
                    "POST", parameters);
            try {
                int success = json.getInt("success");
                if (success == 1) {
                    appDetailPictures = json.getJSONArray("images");
                    for (int i = 0; i < appDetailPictures.length(); i++) {
                        JSONObject c = appDetailPictures.getJSONObject(i);
                        // Storing each json item in variable
                        String picname = c.getString("picture");
                        image_path = "http://www.himbimarket.com/masterApp/"
                                .concat(picname);
                        urlse.add(image_path);
                    }

                }
            } catch (Exception e) {

                // TODO: handle exception
            }

            return null;
        }

        @Override
        protected void onPostExecute(String result) {

            Toast.makeText(getApplicationContext(), urlse.get(2),
                    Toast.LENGTH_LONG).show();

             app_gallery.setAdapter(new ImageGalleryAdapter());

        }



    }

    public class ImageGalleryAdapter extends BaseAdapter {

        @Override
        public int getCount() {
            return urlse.size();
        }

        @Override
        public Object getItem(int position) {
            return position;
        }

        @Override
        public long getItemId(int position) {
            return position;
        }

        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            ImageView imageView = (ImageView) convertView;
            if (imageView == null) {
                imageView = (ImageView) getLayoutInflater().inflate(
                        R.layout.item_gallery_image, parent, false);
            }

            ImageLoader.displayImage(urlse.get(position), imageView);
            return imageView;
        }
    }

    }
当他尝试加载imageview时,适配器出现问题

这是app_detail.xml

        <?xml version="1.0" encoding="utf-8"?>
    <ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:background="@drawable/app_detail_back_image" >

        <LinearLayout
            xmlns:android="http://schemas.android.com/apk/res/android"
            android:layout_width="match_parent"
            android:layout_height="fill_parent"
            android:background="@drawable/app_detail_back_image"
            android:orientation="vertical" >

            <RelativeLayout
                android:id="@+id/loadingPanelAppDetailHeader"
                style="@style/GenericProgressBackground"
                android:layout_height="fill_parent" >

                <ProgressBar style="@style/GenericProgressIndicator" />
            </RelativeLayout>

            <LinearLayout
                android:id="@+id/app_detail_header"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:divider="@drawable/divider"
                android:paddingBottom="5dp"
                android:paddingLeft="5dp"
                android:paddingTop="5dp" >

                <ImageView
                    android:id="@+id/singleAppDetailImage"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:src="@drawable/nopic" />

                <RelativeLayout
                    android:id="@+id/app_detail_header_content"
                    android:layout_width="wrap_content"
                    android:layout_height="match_parent" >

                    <includes.TextResize
                        android:id="@+id/app_detail_title"
                        android:layout_width="fill_parent"
                        android:layout_height="wrap_content"
                        android:layout_alignParentTop="true"
                        android:maxLines="2"
                        android:text="First Application"
                        android:textColor="@color/himbi_apps_color"
                        android:textSize="22sp" />

                    <Button
                        android:id="@+id/app_detail_price"
                        android:layout_width="fill_parent"
                        android:layout_height="wrap_content"
                        android:layout_alignParentBottom="true"
                        android:layout_alignParentRight="true"
                        android:background="@drawable/app_detail_price_back"
                        android:text="Button" />

                    <TextView
                        android:id="@+id/app_detail_developer"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_alignParentLeft="true"
                        android:layout_below="@+id/app_detail_title"
                        android:text="TextView"
                        android:textSize="14sp" />
                </RelativeLayout>
            </LinearLayout>

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="150dp" >

                <Gallery
                    android:id="@+id/app_gallery"
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center_vertical"
                    android:spacing="1dip" />
            </LinearLayout>

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content" >

                <RelativeLayout
                    android:layout_width="fill_parent"
                    android:layout_height="match_parent" >

                    <RatingBar
                        android:id="@+id/app_detail_rating"
                        style="?android:attr/ratingBarStyleSmall"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content" />

                    <TextView
                        android:id="@+id/app_date"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_alignParentRight="true"
                        android:layout_alignParentTop="true"
                        android:text="Small Tijkjext"
                        android:textAppearance="?android:attr/textAppearanceSmall" />
                </RelativeLayout>
            </LinearLayout>

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content" >

                <RelativeLayout
                    android:layout_width="fill_parent"
                    android:layout_height="match_parent" >

                    <TextView
                        android:id="@+id/description_holder"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_alignParentLeft="true"
                        android:layout_alignParentTop="true"
                        android:text="Description Holder" />
                </RelativeLayout>
            </LinearLayout>

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content" >

                <RelativeLayout
                    android:layout_width="fill_parent"
                    android:layout_height="match_parent"
                    android:layout_marginLeft="20dp" >

                    <TextView
                        android:id="@+id/textView2"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_alignParentLeft="true"
                        android:layout_alignParentTop="true"
                        android:text="@string/rating"
                        android:textAppearance="?android:attr/textAppearanceMedium"
                        android:textColor="@color/himbi_color" />


                    <RelativeLayout
                        android:id="@+id/relativeLayout1"
                        android:layout_width="100dp"
                        android:layout_height="100dp"
                        android:layout_margin="25dp"
                        android:layout_toRightOf="@+id/relativeLayout2" >

                        <TextView
                            android:id="@+id/rating_ff_text"
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content"
                            android:layout_alignRight="@+id/textView8"
                            android:layout_centerVertical="true"
                            android:gravity="center_horizontal"
                            android:text="4.5"
                            android:textAppearance="?android:attr/textAppearanceLarge"
                            android:textColor="@color/himbi_apps_color" />

                        <RatingBar
                            android:id="@+id/rating_ff"
                            style="?android:attr/ratingBarStyleSmall"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_below="@+id/rating_ff_text"
                            android:layout_centerHorizontal="true"
                            android:padding="2dp" />

                        <TextView
                            android:id="@+id/textView8"
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content"
                            android:layout_alignParentLeft="true"
                            android:layout_alignParentTop="true"
                            android:background="#a0a0a0"
                            android:gravity="center_horizontal"
                            android:text="Rating"
                            android:textAppearance="?android:attr/textAppearanceMedium"
                            android:textColor="@color/header" />
                    </RelativeLayout>
                </RelativeLayout>
            </LinearLayout>
        </LinearLayout>

    </ScrollView>

以及用于充气的xml:

      <?xml version="1.0" encoding="utf-8"?>
    <Gallery xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/gallery"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="center_vertical"
        android:spacing="1dip" />

Android版本是4.0.1,UIL是最新版本

谢谢您

ImageLoader.getInstance().DisplayImage…

ImageLoader.getInstance().DisplayImage…

1)确保您正在应用程序类中初始化ImageLoader实例:

public class MyApplication extends Application {
@Override
public void onCreate() {
    ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(getApplicationContext()).build();
    ImageLoader.getInstance().init(config);
}
}
2) 另外,在清单中定义此类:

    < application
            android:name=".MyApplication">
            ......
/>
4) 最后,使用它:

        imageLoader.displayImage(urlse.get(position), imageView);
1) 确保正在初始化应用程序类中的ImageLoader实例:

public class MyApplication extends Application {
@Override
public void onCreate() {
    ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(getApplicationContext()).build();
    ImageLoader.getInstance().init(config);
}
}
2) 另外,在清单中定义此类:

    < application
            android:name=".MyApplication">
            ......
/>
4) 最后,使用它:

        imageLoader.displayImage(urlse.get(position), imageView);

问题是ImageLoader.getInstance().DisplayImage…,这是我没有调用的getInstance方法。我需要15个声誉,但我还没有。我保证,我会回来添加一个升级投票。问题是ImageLoader.getInstance().DisplayImage…,我没有调用过的getInstance方法。我需要15个声誉,但我还没有。我保证,我会回来投一票。