显示来自android数据库的图像

赛义德

我有一个本地数据库,我想从中获取 res id(字符串保存)并在应用程序中显示,我还有一个回收器视图,我想在单击项目后显示图像。

    public class AdapterApp extends RecyclerView.Adapter<AdapterApp.AdapterViewHolder>{

  public static class AdapterViewHolder extends RecyclerView.ViewHolder{

    public TextView txtDescription;
    public ViewGroup layoutRoot;
    public TextView txtTitle;
    public ImageView imgDesc;

public AdapterViewHolder(View itemView) {
  super(itemView);
  txtTitle = (TextView) itemView.findViewById(R.id.txtTitle);
  txtDescription = (TextView) itemView.findViewById(R.id.txtDesc);
  layoutRoot = (ViewGroup) itemView.findViewById(R.id.layoutRoot);
  imgDesc = (ImageView) itemView.findViewById(R.id.imgDesc);

}
  }

  private ArrayList<StructApp> names  = new ArrayList<StructApp>();

  public AdapterApp(ArrayList<StructApp> names){
    this.names = names;
  }

  @Override
  public AdapterViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) {
    View view = G.inflater.from(viewGroup.getContext()).inflate(R.layout.adapter_app,viewGroup,false);
    return new AdapterViewHolder(view);
  }

  @Override
  public void onBindViewHolder(final AdapterViewHolder adapterViewHolder, final int i) {
    final StructApp name = names.get(i);
    adapterViewHolder.txtTitle.setText(name.title);


    adapterViewHolder.layoutRoot.setOnClickListener(new View.OnClickListener() {
  @Override
  public void onClick(View v) {
   Intent intent = new Intent(G.currentActivity,ActivityDesc.class);
    intent.putExtra("description",name.description);



    G.currentActivity.startActivity(intent);
  }
});

  }

  @Override
  public int getItemCount() {
    return names.size();
  }



  @Override
  public void onAttachedToRecyclerView(RecyclerView recyclerView) {
    super.onAttachedToRecyclerView(recyclerView);
  }
}

数据库活动:

public class ActivityTitleEngineer extends ActivityEnhanced {

  private RecyclerView                     recyclerView;
  private AdapterApp           adapter;

  private ArrayList<StructApp> applications = new ArrayList<>();

  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_reshte_math);



recyclerView = (RecyclerView) findViewById(R.id.recyclerView);
recyclerView.setHasFixedSize(true);
LinearLayoutManager manager = new LinearLayoutManager(G.context);
manager.setOrientation(LinearLayoutManager.VERTICAL);
recyclerView.setLayoutManager(manager);
adapter = new AdapterApp(G.reshte);
populateFromDatabase();
recyclerView.setAdapter(adapter);


  }


  public void populateFromDatabase() {
    G.reshte.clear();
    DataBaseConnection db = new DataBaseConnection(this, "database", 4);
    final SQLiteDatabase database = db.getReadableDatabase();

Cursor cursor = database.rawQuery("SELECT * FROM Reshte ", null);
while (cursor.moveToNext()) {
  StructApp application = new StructApp();
  application.description = cursor.getString(cursor.getColumnIndex("description"));
  application.title = cursor.getString(cursor.getColumnIndex("title"));
  application.imgDesc = cursor.getString(cursor.getColumnIndex("img"));




  G.reshte.add(application);

}
cursor.close();

  }
}

显示图像的活动:

public class ActivityDesc extends AppCompatActivity {

  private TextView txtDesc;
  private ImageView imgDesc;

  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_reshte_desc);



txtDesc = (TextView) findViewById(R.id.txtDesc);
imgDesc = (ImageView) findViewById(R.id.imgDesc);
Bundle extras = getIntent().getExtras();
if(extras!= null){
  String desc = extras.getString("description");
  txtDesc.setText(desc);
}



  }
}
罗德里克斯

试试这个方法:)

StorageReference islandRef = MainGameFragment.storageReference.child("Capture.PNG");
                final long ONE_MEGABYTE = 1024 * 1024;
                islandRef.getBytes(ONE_MEGABYTE).addOnSuccessListener(new OnSuccessListener<byte[]>() {
                    @Override
                    public void onSuccess(byte[] bytes) {
                        ByteArrayInputStream imageStream = new ByteArrayInputStream(bytes);
                        Bitmap bitmap = BitmapFactory.decodeStream(imageStream);
                        imageSettings.setImageBitmap(bitmap);
                        settingsText4.setText("Click to visit site for more information");
                        settingsText4.setOnClickListener(new View.OnClickListener() {
                            @Override
                            public void onClick(View v) {
                                String url = "site";
                                Intent i = new Intent(Intent.ACTION_VIEW);
                                i.setData(Uri.parse(url));
                                startActivity(i);
                            }
                        });
                        mProgress.setVisibility(View.GONE);
                    }
                }).addOnFailureListener(new OnFailureListener() {
                    @Override
                    public void onFailure(@NonNull Exception exception) {

                    }
                });

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

显示来自数据库的图像

来自分类Dev

显示来自 phpMyadmin 数据库的图像

来自分类Dev

在模式引导窗口中显示来自数据库的图像

来自分类Dev

显示来自MySQL数据库中路径的图像

来自分类Dev

来自sqlite数据库的ios图像显示

来自分类Dev

显示来自数据库ASP.Net的图像

来自分类Dev

在mysql数据库中显示来自路径的图像

来自分类Dev

如何使用php显示来自数据库mysql的图像?

来自分类Dev

显示来自sqlite数据库的所有图像

来自分类Dev

显示来自数据库的Restfull API的链接图像

来自分类Dev

PHP-无法显示src来自数据库的图像

来自分类Dev

Laravel 显示来自数据库中路径的图像

来自分类Dev

在网格中显示来自数据库的图像 - laravel

来自分类Dev

谷歌地图api显示来自数据库的图像

来自分类Dev

PHP / MYSQL - 显示来自数据库问题的图像

来自分类Dev

在 Laravel 中显示来自数据库的数组格式图像

来自分类Dev

列表视图未显示来自Android数据库的数据

来自分类Dev

显示来自数据库PDO的数据

来自分类Dev

在JSF页面中将图像显示为来自数据库的byte []作为图形图像

来自分类Dev

如何在Android的Glide中显示数据库图像?

来自分类Dev

在ASP.NET中以src图像显示来自数据库的数据

来自分类Dev

显示来自数据库AngularJS的值

来自分类Dev

显示来自Firebase数据库的消息

来自分类Dev

显示来自数据库单元的信息

来自分类Dev

显示来自数据库的主题标签

来自分类Dev

如何显示来自MySQL数据库的图像的幻灯片

来自分类Dev

如何在PictureBox中显示来自Access数据库的附件图像

来自分类Dev

Yii2显示来自Blob数据库字段的图像

来自分类Dev

在Windows Phone 8中显示来自远程数据库的图像

Related 相关文章

热门标签

归档