在Imageview中设置图像,其中图像的路径存储在sqlite数据库中,而实际图像存储在drawable中

时间:2018-12-24 04:33:18

标签: android

我正在开发一个android词典应用程序。我从sqlite数据库检索文本并在textview中显示文本没有问题,但是在尝试将图像的路径保存到数据库中时遇到了一些问题(将实际图像存储在可绘制资源中文件夹),然后在Imageview中设置图片。

    protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_definition);

    String term=getIntent().getStringExtra("TERM");
    String acronyms=getIntent().getStringExtra("ACRONYMS");
    String wordclass=getIntent().getStringExtra("WORDCLASS");
    String dzongkha=getIntent().getStringExtra("DZONGKHA");
    String defintion=getIntent().getStringExtra("DEFINITION");
    String category=getIntent().getStringExtra("CATEGORY");
    String image=getIntent().getStringExtra("IMAGE");


    TextView termText= (TextView) findViewById(R.id.termtext);
    TextView acronymsText= (TextView) findViewById(R.id.acronymstext);
    TextView wordclassText= (TextView) findViewById(R.id.wordclasstext);
    TextView dzongkhaText= (TextView) findViewById(R.id.dzongkhatext);
    TextView categoryText= (TextView) findViewById(R.id.categorytext);
    TextView definitionText= (TextView) findViewById(R.id.definitiontext);
    ImageView imageText=(ImageView)findViewById(R.id.imagetext);


    termText.setText(term);
    acronymsText.setText(acronyms);
    wordclassText.setText(wordclass);
    dzongkhaText.setText(dzongkha);
    categoryText.setText(category);
    definitionText.setText(defintion);
    imageText.setImage(image);

    }
    }


    Code for sqlite transactions

    public class ViewHolder extends RecyclerView.ViewHolder{
    public Context context;
    public TextView termText;
    public ViewHolder(View itemView, final Context context) {
    super(itemView);
    this.context=context;
    termText=(TextView) itemView.findViewById(R.id.termtext);

    itemView.setOnClickListener(new View.OnClickListener() {
    @Override
            public void onClick(View view) {
                int position=getAdapterPosition();
                DictionaryModel dictionaryModel=data.get(position);

                Intent intent=new Intent(context, DefinitionActivity.class);
                intent.putExtra("TERM",dictionaryModel.getTerm());

              intent.putExtra("DEFINITION",dictionaryModel.getDefinition());
                intent.putExtra("ACRONYMS",dictionaryModel.getAcronyms());
                intent.putExtra("WORDCLASS",dictionaryModel.getWordclass());
                intent.putExtra("DZONGKHAEQUIVALENT",dictionaryModel.
                getDzongkhaequivalent());
                intent.putExtra("CATEGORY",dictionaryModel.getCategory());
                intent.putExtra("IMAGE",dictionaryModel.getImage());

                context.startActivity(intent);
            }
        });

每当用户单击列表视图中的术语时,我希望它显示相关的文本描述和数据库中的图像。

1 个答案:

答案 0 :(得分:0)

解决方案1:

使用:

cordova build android --release


Android Studio project detected
ANDROID_HOME=/Users/me/Library/Android/sdk
JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk-11.0.1.jdk/Contents/Home
Requirements check failed for JDK 1.8
[ERROR] An error occurred while running subprocess cordova.

ll /Library/Java/JavaVirtualMachines/
total 0
drwxr-xr-x  3 root  wheel  96 Jul 14  2015 1.6.0.jdk
drwxr-xr-x  3 root  wheel  96 Dec 23 14:19 jdk-11.0.1.jdk
drwxr-xr-x  3 root  wheel  96 Dec 23 20:00 jdk1.8.0_191.jdk
drwxr-xr-x  3 root  wheel  96 Aug 11  2015 jdk1.8.0_51.jdk

Android studio 3.2
Android SDK 9, 8.1, 7.1.1, 6 installed

ionic info

Ionic:

   ionic (Ionic CLI)  : 4.5.0 (/Users/me/node_modules/ionic)
   Ionic Framework    : ionic-angular 3.9.2
   @ionic/app-scripts : 3.2.0

Cordova:

   cordova (Cordova CLI) : 8.1.2 (cordova-lib@8.1.1)
   Cordova Platforms     : android 7.1.4, ios 4.5.5
   Cordova Plugins       : cordova-plugin-ionic-keyboard 2.0.5, cordova-plugin-ionic-webview 1.1.1, (and 9 other plugins)

System:

   ios-deploy : 1.9.4
   NodeJS     : v11.4.0 (/Users/me/.nvm/versions/node/v11.4.0/bin/node)
   npm        : 6.4.1
   OS         : macOS Mojave
   Xcode      : Xcode 10.1 Build version 10B61

而不是:

imageText.setImageResource(image);

解决方案2:

使用imageText.setImage(image); 库:

Picasso

在Java中执行:

implementation 'com.squareup.picasso:picasso:2.5.2'