在我的應用程序中,我需要在Android中顯示問題以及圖像。我已經在sqlite數據庫中存儲問題並顯示它們。我在資產文件夾中創建了一個文件夾DBimages。現在我所有的圖像都在DBimages文件夾中。如何在sqlite數據庫中存儲圖像並顯示它們?
我創建了兩個類。我能夠顯示來自本地sqlite數據庫的問題和選項,但我無法顯示存儲在assets\DBimages\abc.png
中的圖像。
所有圖像的名稱都存儲在sqlite數據庫表中的圖片列中。但是如何顯示與特定問題相關的圖像。請幫助我解決這個問題。
UserBO.java
public String getQuestion() {
return question;
}
public void setQuestion(String question) {
this.question = question;
}
public String getImage() {
return pictures;
}
public void setImage(String pictures) {
this.pictures = pictures;
}
Select.java
ArrayList<UserBO> usersList = new ArrayList<UserBO>();
for (int i = 0; i < stringList.size(); i++) {
ArrayList<String> list = stringList.get(i);
UserBO user = new UserBO();
try {
user.id = Integer.parseInt(list.get(0));
user.name = list.get(2);
user.question = list.get(3);
user.option1 = list.get(4);
user.option2 = list.get(5);
user.option3 = list.get(6);
user.option4 = list.get(7);
user.option5 = list.get(8);
user.pictures = list.get(9);
user.answer = (list.get(10));
}
catch (Exception e){}
public View getView(int position, View convertView, ViewGroup parent){
View view = convertView;
try{
if (view == null) {
LayoutInflater vi = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
view = vi.inflate(R.layout.list_item, null);
}
final UserBO listItem = mList.get(position);
if (listItem != null) {
((TextView) view.findViewById(R.id.tv_question)).setText(listItem.getQuestion()+"");
((ImageView) view.findViewById(R.id.imageView1)).setImageResource(R.drawable.f);
((RadioButton) view.findViewById(R.id.option1)).setText(listItem.getOption1());
((RadioButton) view.findViewById(R.id.option2)).setText(listItem.getOption2()+"");
((RadioButton) view.findViewById(R.id.option3)).setText(listItem.getOption3()+"");
((RadioButton) view.findViewById(R.id.option4)).setText(listItem.getOption4()+"");
((RadioButton) view.findViewById(R.id.option5)).setText(listItem.getOption5()+"");
}}catch(Exception e){}
return view;
}}
嗨感謝看到輸入反應的例子。我將我的圖像保存在可繪製的文件夾中。現在我需要從sqlite數據庫圖像列中獲取img路徑和圖像名稱。你能舉個例子來說明一下這個示例代碼。提前致謝。 – RaagaSudha
如果您要將圖像存儲在可繪製文件夾中,那麼我不認爲您必須將其存儲在數據庫文件中,只需將圖像重命名爲問題ID或名稱,然後直接使用繪圖文件。 – user370305
嗨,你可以請示例代碼?例如, – RaagaSudha