1

好きな画像を選択できるListViewがあり、うまく機能していますが、問題は他の画像を選択するとクラッシュし、理解できないこのエラーメッセージが表示され、これらの画像はMySqlからのものですデータベース。

アダプターの内容が変更されましたが、ListView は通知を受け取りませんでした。アダプターのコンテンツがバックグラウンド スレッドからではなく、UI スレッドからのみ変更されていることを確認してください。[ListView(16908298、class android.widget.ListView) with Adapter(class car.store.carstore.MobileArrayAdapter)]

事前にサンクス。

マイアダプターはこんな感じ

public class MobileArrayAdapter extends ArrayAdapter<String> {

    private final Context context;
    private final String[] MyCarList = null;
    private ArrayList<String> MyCar = new ArrayList<String>();
    private ArrayList<String> CarImageUrl = new ArrayList<String>();
     //ArrayList<HashMap<String, String>> MyCarList = new ArrayList<HashMap<String, String>>();
     //ArrayList<HashMap<String, String>> CarImageUrl = new ArrayList<HashMap<String, String>>();

    public MobileArrayAdapter(Context context,ArrayList<String> Bname,ArrayList<String> BUrl) {
        super(context, R.layout.list_mobile, Bname);
        this.context = context;
        this.MyCar = Bname;
        this.CarImageUrl = BUrl;
    }


    public View getView(int position, View convertView, ViewGroup parent) {
        LayoutInflater inflater = (LayoutInflater) context
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        View rowView = inflater.inflate(R.layout.list_mobile, parent, false);
        TextView textView = (TextView) rowView.findViewById(R.id.label);
        ImageView imageView = (ImageView) rowView.findViewById(R.id.logo);
        textView.setText(MyCar.get(position));
        Bitmap bitmap = null;
        // Change icon based on name
        JSONObject json = JSONfunctions.getJSONfromURL("http://10.0.2.2/php/car.php");
           // http://api.geonames.org/earthquakesJSON?north=44.1&south=-9.9&east=-22.4&west=55.2&username=demo  
            try{                
                JSONArray  earthquakes = json.getJSONArray("cars");

                //for(position=0;position<earthquakes.length();position++){
                    JSONObject e = earthquakes.getJSONObject(position);
                    String BB = e.getString("carname");
                    MyCar.add(BB);

                    String UU = e.getString("carimage");
                    CarImageUrl.add(UU);

                //}

            }catch(JSONException e){
                 Log.e("log_tag", "Error parsing data "+e.toString());
            }


            String s = MyCar.get(position);
            String i = CarImageUrl.get(position);

            System.out.println(s);
            System.out.println(i);


            try {
                bitmap = BitmapFactory.decodeStream((InputStream)new URL(i).getContent());
            } catch (MalformedURLException err) {
                // TODO Auto-generated catch block
                err.printStackTrace();
            } catch (IOException err) {
                // TODO Auto-generated catch block
                err.printStackTrace();
            }

            //if (!s.equals("")) {
                imageView.setImageBitmap(bitmap);
            //} else {
            System.out.println("Bitmap image: "+position+"="+bitmap);
                //imageView.setImageResource(R.drawable.android_logo);
            //}


        return rowView;
    }
4

2 に答える 2

1

リストにアイテムを追加するときに notifyDataSetChanged() を呼び出してみてください。requestLayout() もうまくいくかもしれません。

于 2012-07-02T12:43:47.627 に答える
0

最初にWebサービスからすべての値を取得してから、それをアダプターに渡します

于 2012-07-02T13:09:00.997 に答える