0

AsyncTask new LoadBookBuyInfo().execute(); への呼び出しで、「LoadBookBuyInfo を型に解決できません」というエラーが表示されます。私はフラグメントを使用しており、インターネットで答えを探しましたが、役に立ちませんでした。どんな助けでも大歓迎です、ありがとう。

これが私のコードです:

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, 
        Bundle savedInstanceState) {

    View view = inflater.inflate(R.layout.buy_tbfrag, container, false);

    //bookLV = (ListView)view.findViewById(R.id.list);
    //bookLV = getListView();
    bookLV = (ListView)view.findViewById(android.R.id.list);

    //enables filtering for the contents of the given ListView bookLV
    bookLV.setTextFilterEnabled(true);

    //Search inputed book title
    titleSearch = (EditText)view.findViewById(R.id.titleSearch);


    return view;
}


@Override
public void onActivityCreated(Bundle savedInstanceState){

    System.out.println("onActivityCreated executed");

    bookArray = new ArrayList<Bookinfo>();

    //**************************************************************************************//
    //*******************New Async Task & JSON Parser code starts here**********************//
    //**************************************************************************************//

    //Load bookArray in Background Thread
    new LoadBookBuyInfo().execute();


    //Background AsyncTask to load all BookBuyInfo by making Http Request
    class LoadBookBuyInfo extends AsyncTask<String, String, String> {

        //Show Progress Dialog before starting background thread
        @Override
        protected void onPreExecute() {
            super.onPreExecute();

            //pDialog = new ProgressDialog(BuyFragTab); //might can only be activity
            pDialog = new ProgressDialog(getActivity());//might can only be activity
            pDialog.setMessage("Loading Books...");
            pDialog.setIndeterminate(false);
            pDialog.setCancelable(false);
            pDialog.show();
        }

        //Get BookBuyInfo Data
        protected String doInBackground(String... arg0) {
            //Building parameters
            ArrayList<NameValuePair> bookValues = new ArrayList<NameValuePair>();

            //getting JSON string from URL
            JSONObject json = jsonParser.makeHttpRequest(BOOKBUY_URL, "GET", bookValues);

            //Check logcat for JSON response
            Log.d("Book Buy JSON: ", json.toString());

            //Get JSON Data
            try {
                bookBuyInfo = json.getJSONArray("books");

                //bookArray = new ArrayList<Bookinfo>();
                //loop through all books and load data
                for (int i = 0; i < bookBuyInfo.length(); i++) {
                    JSONObject b = bookBuyInfo.getJSONObject(i);
                    ...
                    (book code setup)}
            }
            catch (JSONException e) {
                e.printStackTrace();
            }

            return null;
        }

    //}

        //After completing background task, dismiss the progress dialog
        protected void onPostExecute(String file_url) { // might need to be (String result) here
            //dismiss the dialog after getting all the records
            pDialog.dismiss();
            //update UI from background thread
            //runOnUiThread(new Runnable() {
            getActivity().runOnUiThread(new Runnable() {
                public void run() {
                    //updating parsed JSON data into ListView
                    adapter = new MyCustomAdapter(getActivity(), R.layout.buy_tbfrag, bookArray);
                    bookLV.setAdapter(adapter);
                }
            });
        }
    }
4

1 に答える 1

1

AsyncTask クラスを onActivityCreated メソッド内に配置したようです。AsyncTask クラス全体をこのメソッドの外に移動し、そこから呼び出します。

于 2013-03-29T23:01:09.233 に答える