7

您好,我正在为我的应用程序使用 Stetho 调试平台。我在我的 gradle 中添加了 Stetho,如下所示

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.1.1'
compile 'com.android.support:design:23.1.1'
compile 'com.facebook.stetho:stetho:1.2.0'

}

并将其初始化为 onCreate 方法,如下所示

 @Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    Stetho.initializeWithDefaults(this);
    findElementsByIds();
    addDataIntoDBs();
    initData();
}

我为演示创建了类别表(作为 cat_id 和 cat_name 列)并在其中添加了一些条目,请参阅 屏幕截图。

谁能告诉它为什么显示与图像中同名的两列

我为创建表所做的代码

public class DBHelper extends SQLiteOpenHelper{

private static String DATABASE_NAME = "citizan.db";
private static int DATABASE_VERSION = 1;
private static DBHelper dbHelperInstance = null;
private static SQLiteDatabase dbInstance= null;

public static String CATEGORY_TABLE = "category";
public static String CAT_ID = "cat_id";
public static String CAT_NAME = "cat_name";
private String CREATE_CATEGORY_TABLE = "create table "+CATEGORY_TABLE + "("+CAT_ID+" Integer primary key autoincrement, " +CAT_NAME+ " text"+")";
private String DROP_CATEGORY_TABLE = "drop table if exists "+CATEGORY_TABLE;

private DBHelper(Context context)
{
    super(context, AppConstants.DATABASE_NAME, null,AppConstants.DATABASE_VERSION);

}

public static  synchronized  DBHelper getInstance(Context context) {
    if(dbHelperInstance == null)
    {
        dbHelperInstance = new DBHelper(context);
    }
    return dbHelperInstance;
}

@Override
public void onCreate(SQLiteDatabase db) {
    db.execSQL(CREATE_CATEGORY_TABLE);
}

@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
     db.execSQL(DROP_CATEGORY_TABLE);
     onCreate(db);
}

public static  void openConnection()
{
    if(dbInstance == null)
    {
        dbInstance = dbHelperInstance.getWritableDatabase();
    }
}

public void addCategories(String[] catArray)  {
   openConnection();
    ContentValues values = new ContentValues();
    for (int i=0;i<catArray.length;i++)
    {
        values.put(CAT_NAME, catArray[i]);
        dbInstance.insert(CATEGORY_TABLE,null,values);
    }
}

}

4

0 回答 0