android listview适配器的错误-问答-阿里云开发者社区-阿里云

开发者社区> 问答> 正文
阿里云
为了无法计算的价值
打开APP
阿里云APP内打开

android listview适配器的错误

具体报错见下面。高手求解决·····
先贴代码,下面是PointMgrActivity.java
package com.app.bluetoothpro;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import com.app.DB.DBManager;
import com.app.DB.PointClass;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.ListView;
import android.widget.SimpleAdapter;
public class PointMgrActivity extends Activity {
protected static final String ACTIVITY_TAG = "LogDemo";
private DBManager dbManager;
public SQLiteDatabase db;
String gID;
String pStatu;

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);
setContentView(R.layout.point_mgr);
dbManager = new DBManager(this);

/*
 * Points person = new Points(); person.pid = "id1"; person.pstatu =
 * "OFF"; db.execSQL("INSERT INTO points VALUES (?, ?)", new
 * Object[]{person.pid, person.pstatu});
 */
addbtn();

}

/ 添加add方法 */
public void add() {

ArrayList<PointClass> persons = new ArrayList<PointClass>();

PointClass person = new PointClass(gID, pStatu);

persons.add(person);
dbManager.add(persons);

}

  • / 添加query()查询方法 **/
  1. void query() {
    List persons = dbManager.query();
    ArrayList> listItem = new ArrayList>();
    for (PointClass person : persons) {

       HashMap<String, Object> map = new HashMap<String, Object>();
       map.put("pid", person.pid);
       map.put("pstatu", getstatu(pStatu));
       listItem.add(map);
       Log.d(ACTIVITY_TAG, person.pid + " +++++++++++++++++++++++++++ "
               + getstatu(pStatu));

    }
    ListView list = (ListView) findViewById(R.id.pointListView);
    SimpleAdapter listItemAdapter = new SimpleAdapter(this, listItem,

           R.layout.point_mgr_list_item,
           new String[] { "pointsID", "pointsStatu" },
           new int[] { R.id.pointsID, R.id.pointsStatu });

    list.setAdapter(listItemAdapter);

    list.setOnItemClickListener(new OnItemClickListener() {

       @Override
       public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
               long arg3) {
           // TODO Auto-generated method stub
       }

    });
    }

private Object getstatu(String str) {

// TODO Auto-generated method stub
if (str.equals("ON")) {
    return R.drawable.led_green;
} else {
    return R.drawable.led_red;
}

}

/ 为添加按钮添加事件 */

void addbtn() {

ImageButton ib_add = (ImageButton) findViewById(R.id.addpoint);
ib_add.setOnClickListener(new OnClickListener() {

    @Override
    public void onClick(View v) {
        LayoutInflater inflater = getLayoutInflater();
        final View layout = inflater.inflate(R.layout.add_dialog,
                (ViewGroup) findViewById(R.id.dialog));
        new AlertDialog.Builder(PointMgrActivity.this)
                .setTitle("请添加节点")
                .setView(layout)
                .setPositiveButton("确定",
                        new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog,
                                    int which) {
                                EditText et = (EditText) layout
                                        .findViewById(R.id.addID);
                                gID = et.getText().toString();
                                pStatu = "OFF";
                                /***************************************** 将输入的id,状态写入map中 **************/
                                Log.i(PointMgrActivity.ACTIVITY_TAG,
                                        gID + "   " + pStatu);
                                // insert(db,gID,pStatu);
                                // close(db);
                                add();
                                query();

                                /******************** 调试代码 ********************************************/
                                Log.i(PointMgrActivity.ACTIVITY_TAG,
                                        gID);
                                /***************************************************************************************/

                            }
                        })
                .setNegativeButton("取消",
                        new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog,
                                    int which) {

                            }
                        }).show();
    }

});

}
}
layout.xml布局文件中有listview,有 两列textview imageview ,
上面query()方法是将从sqlite查询的数据在listview显示,下面是适配器代码:
ListView list = (ListView) findViewById(R.id.pointListView);
SimpleAdapter listItemAdapter = new SimpleAdapter(this, listItem,
R.layout.point_mgr_list_item,
new String[] { "pointsID", "pointsStatu" },
new int[] { R.id.pointsID, R.id.pointsStatu });
list.setAdapter(listItemAdapter);
log调试得到正确从数据库查询数据,就是不listview显示数据.
运行报错:
10-23 10:56:36.670: E/BitmapFactory(12701): Unable to decode stream: java.io.FileNotFoundException: /: open failed: EISDIR (Is a directory)

展开
收起
a123456678 2016-07-18 15:32:33 2081 0
1 条回答
写回答
取消 提交回答
  • a123456678

    适配器参数写错了
    SimpleAdapter listItemAdapter = new SimpleAdapter(this, listItem, R.layout.point_mgr_list_item, new String[] { "pid", "pstatu" }, new int[] { R.id.pointsID, R.id.pointsStatu }); list.setAdapter(listItemAdapter);

    2019-07-17 19:57:59
    赞同 展开评论 打赏
问答排行榜
最热
最新
相关电子书
更多
Android组件化实现
立即下载
蚂蚁聚宝Android秒级编译—— Freeline
立即下载
Android插件化:从入门到放弃
立即下载