中的自定义数组列表嗨我开发了一个android应用程序,我从mysql中检索类别并将它们设置为自定义数组列表并将它们显示为按钮。如何将项目添加到android
现在我想从本地sqlite数据库中带来相同的类别,并将它们显示为按钮。 但在第一种情况下,我已经创建了一个自定义列表数组,并且正在分配响应并将这些项目添加到该列表并显示为按钮。
但是,当我试图从本地SQLite数据库中获取它们,我没有得到如何将值添加到数组列表
这是怎么了,我从MySQL检索
@Override
protected void onPostExecute(String resp) {
progressDialog.dismiss();
if(resp ==null) {
if (categoriesResp != null) {
//Toast.makeText(getApplicationContext(), ""+categoriesResp, 5000).show();
updateUi(categoriesResp.response);
} else
Toast.makeText(Categories.this, "Something went wrong", Toast.LENGTH_LONG).show();
}else
if(!Utils.isNetConnected(Categories.this))
Utils.showDialog(Categories.this);
else
Toast.makeText(Categories.this, resp, Toast.LENGTH_LONG).show();
}
}
这是我Uiupdate()方法
private void Uiupdate(List<Category> response) {
int i = 0;
for(Category category:response){
LayoutInflater inflater = getLayoutInflater();
View row = inflater.inflate(R.layout.my_category, null, false);
Button button = (Button) row.findViewById(R.id.buttonCategory);
button.setText(category.CategoryName);
button.setTag(category.CategoryID);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if(Utils.isNetConnected(Categories.this)) {
Intent intent = new Intent(Categories.this, MainActivity.class);
intent.putExtra("categoryId", (String) v.getTag());
intent.putExtra("categoryName", ((Button) v).getText());
startActivity(intent);
}else
Utils.showDialog(Categories.this);
}
});
if(i%2 == 0)
button.setBackgroundResource(R.drawable.label_with_arrow);
else
button.setBackgroundResource(R.drawable.field_with_arrow);
i++;
categoriesContainer.addView(row);
}
}
这是我的本地SQLite方法
public void loadCategories()
{
Toast.makeText(getApplicationContext(), "Loaded", 5000).show();
db = this.openOrCreateDatabase("tafrider", MODE_PRIVATE, null);
c = db.rawQuery("SELECT CategoryID,CategoryName FROM categories WHERE EventID= 0 and status= 1 ",null);
List<Category> categories = new ArrayList<Category>();
while(c.moveToNext()){
categoryName = c.getString(c.getColumnIndex("CategoryName"));
Category c1 = new Category();
c1.CategoryName= categoryName;
Category.add(c1);
// Toast.makeText(getApplicationContext(), ""+categoryName, 5000).show();
}
Toast.makeText(getApplicationContext(), ""+categories.size(), 5000).show();
updateUi(categories);
}
在这里,我面临与categories.add(categoryName)它显示错误 如何解决这个问题..?
“它显示错误”是什么错误? – codeMagic
@codeMagic类型列表中的方法add(类别)不适用于参数(String)这是错误 –