我一直在我的sqlite DataBase [9999] [8888]中使用方括号获取数据,我需要的是没有[]的简单数据。
public class AddReminders extends Activity implements OnClickListener {
private Button btn_addrecord;
private EditText txtpname;
String[] versionNames= new String[]{"8888"};
String[] versionNames1= new String[]{"9999"};
ProductModel pm;
DatabaseHelper db;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.add_reminder);
db = new DatabaseHelper(getApplicationContext());
db.getWritableDatabase();
pm = new ProductModel();
pm.idno = (Arrays.toString(versionNames));
Log.i("reminderidno", "" + pm.idno );
db.addProduct(pm);
db = new DatabaseHelper(getApplicationContext());
db.getWritableDatabase();
pm = new ProductModel();
pm.idno = (Arrays.toString(versionNames1));
Log.i("reminderidno", "" + pm.idno );
db.addProduct(pm);
txtpname = (EditText) findViewById(R.id.myEditText);
btn_addrecord = (Button) findViewById(R.id.button1);
btn_addrecord.setOnClickListener(this);
}
@Override
public void onClick(View v) {
DatabaseHelper db;
ProductModel pm;
// TODO Auto-generated method stub
switch (v.getId()) {
case R.id.button1:
if (txtpname.getText().toString().equals("")
) {
Toast.makeText(AddReminders.this, "Please add values..",
Toast.LENGTH_LONG).show();
} else {
db = new DatabaseHelper(getApplicationContext());
db.getWritableDatabase();
pm = new ProductModel();
pm.idno = (txtpname.getText().toString());
Log.i("reminderidno", "" + pm.idno );
db.addProduct(pm);
Toast.makeText(AddReminders.this, "Record Added successfully.",
Toast.LENGTH_LONG).show();
finish();
}
break;
default:
break;
}
}
}
这是我的日志
12-02 19:28:39.398: I/reminderidno(7827): [8888]
12-02 19:28:39.448: I/reminderidno(7827): [9999]
要明确我需要8888没有方括号 提前谢谢
答案 0 :(得分:1)
正如你在数组中只使用一个元素那样用sting替换数组作为String versionNames =" 8888&#34 ;;并替换pm.idno =(Arrays.toString(versionNames));到pm.idno = versionNames;类似于versionNames1