中的自定義數組列表嗨我開發了一個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)這是錯誤 –