-3

我有一個本地數據庫,我想從它(字符串保存)獲取res id並在應用程序中顯示,我也有一個回收視圖,並且我想在點擊項目後顯示圖像。從android數據庫中顯示圖像

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); 
} 



    } 
} 

回答

0

試試這個方法:)

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) { 

        } 
       }); 
+0

在那裏我可以用這個方法? – Seyyedh