điều này có thể là một thông điệp dài nhưng tôi muốn đưa ra một câu hỏi rõ ràng cho tất cả người dùng stackoverflow. Những gì tôi đã làm là tạo một static String của mảng bên trong một lớp học mà được binded trên GridView của tôiChuỗi tĩnh của chuỗi phải được chuyển đổi từ cơ sở dữ liệu
class ParserArrayList {
//some declaration and codes here
private String [] imageCaptionId = {
"My First Medal",
"You ...",
"The ...",
"Gimme ...",
"A ...",
"Seven ...",
".....City",
".... Madness",
"Loyal...",
".....",
"...",
"Champion..."
};
}
Và tự ràng buộc nó trên public class ImageAdapter kéo dài BaseAdapter
public class ImageAdapter extends BaseAdapter{
//some declaration and variables here
public View getView(int position, View convertView, ViewGroup parent) {
View v;
ParserArrayList arrayImage = new ParserArrayList();
String[] imagetext = arrayImage.getImageCaptionId();
if (convertView == null) {
//some stuff here
}
//some stuff here
return v;
}
Như bạn thấy tôi kêu gọi 'ImageCaptionId' của ParserArrayList và gửi nó tới một chuỗi mảng khác, trong đó tôi khai báo 'imagetext'
Mọi thứ hoạt động tốt cho đến khi tôi phát hiện ra rằng 'imageCaptionId' của mảng phải dựa trên cơ sở dữ liệu cục bộ Ive đã cố gắng sử dụng mã này, nhưng tôi không thể hoàn thành vì
class ParserArrayList {
//added this code
public SQLiteAdapter sqlAdapter;
//and this one
public void showData(){
sqlAdapter = new SQLiteAdapter(this);
String str = "Select dTitle from achievement_tb where version =0 order by ID ASC;";
sqlAdapter.openToRead();
Cursor c =sqlAdapter.read(str);
sqlAdapter.close();
}
}
Thứ nhất: Tôi không biết làm thế nào để ràng buộc nó vào mảng
Thứ hai: Tôi tạo ra nó bên ParserArrayList và nó mang lại cho tôi một lỗi nói Các constructor SQLiteAdapter (ParserArrayList) là undefined (Điều này đã được thực hiện)
ông có thể giúp tôi thưa ông
E DIT Đây là những gì tôi đang cố gắng để thực hiện hoặc logic của tôi
trên lớp ParserArrayList của tôi, tôi đang cố gắng để thêm mã này (Tôi không biết nếu điều này là đúng)
public String[] showImageCaption(){
String imageCaptionIds [];
sqlAdapter = new SQLiteAdapter(mContext);
String str = "Select dTitle from achievement_tb where version =0 order by ID ASC;";
sqlAdapter.openToRead();
Cursor c =sqlAdapter.read(str);
imageCaptionIds [c.getCount()];
sqlAdapter.close();
return imageCaptionIds;
}
mà mang lại cho tôi một lỗi nói lỗi cú pháp, chèn "AssignmentOperator Expression" để hoàn thành Biểu
giờ trở đi ImageAdapter của tôi kéo dài BaseAdapter đây là mã của tôi
public View getView(int position, View convertView, ViewGroup parent) {
View v;
ParserArrayList arrayImage = new ParserArrayList(mContext);
newArrayList2 = arrayImage.getArraylist();
**String[] imagetext = arrayImage.showImageCaption();**
if (convertView == null) { // if it's not recycled, initialize some attributes
LayoutInflater li = getLayoutInflater();
v = li.inflate(R.layout.medal_grid, null);
}
else
{
v = convertView;
}
TextView tv = (TextView)
v.findViewById(R.id.grid_item_label);
**tv.setText(imagetext[position]);**
ImageView iv = (ImageView)v.findViewById(R.id.grid_item_image);
iv.setImageResource((Integer) newArrayList2.get(position));
return v;
}
Logic của tôi là tôi sẽ ràng buộc nó vào mảng của tôi về chuỗi bên ParserArrayList (trong đó nó sẽ trở lại imageCaptionIds) và thiết lập nó trên một TextView
Hope ai đó có thể trả lời câu hỏi nguyên nhân này tôi có thể gặp phải nó cũng^_^ – Janwel
vấn đề thứ hai xảy ra bởi vì bạn đang đi qua các tham số sai cho 'sqlAdapter = new SQLiteAdapter (này); 'This' của bạn tham chiếu đến' ParserArrayList' (là một đối tượng bạn đã tạo), bạn nên tạo một 'SQLiteOpenHelper' để truy cập cơ sở dữ liệu của bạn. Xem [hướng dẫn này] (http://www.vogella.com/articles/AndroidSQLite/article.html) – Aprian
bị thử đọc bài viết của bạn thưa ông –