I am new to Android and am facing a problem when displaying an image from a server based on its name from Sqlite
namely: I only saved the image name (text) in the SQLite database (column name images), and I want to download images from the server based on the sqlite image name that the image should display in imageview
On the server, I create a folder such as "Cars" in this folder, I store images with the names of the cars .. but in sqlite I just add carname in text format with .jpeg
I have two column names in my database:
- car name first
- Second - Car Detail
When the user selects the name of the car, in the next step the user can see the details of the car with images. Here I display the details, but I do not know how to display car images from the server
thanks
Here is my code:
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.detail_activity); detailtext= (TextView) findViewById(R.id.detail); imageView= (ImageView) findViewById(R.id.images); Intent intent= getIntent(); final String selectedData = intent.getStringExtra("selectedItem"); actionBar.setTitle(selectedData); dbHelper = new SqlLiteDbHelper(this); try { dbHelper.openDataBase(); } catch (SQLException e) { e.printStackTrace(); } sqLiteDatabase = dbHelper.getReadableDatabase(); cursor=dbHelper.getdetails(sqLiteDatabase, selectedData); if (cursor.moveToFirst()) { detailtext.setText(cursor.getString(0)); String imagename = cursor.getString(1); String imageUrl = "http://your_server/car/" + imagename ; Picasso.with(this).load(imageUrl).into(imageView ); }
Note. The image field is the 4th column of http://i.stack.imgur.com/lqvOQ.png and on the server I put the image in www.server.com/cars/carnames.jpg
in sqlite i just paste the image name with .jpg ex: carnames.jpg
SqliteDbHelper
public Cursor getdetails(SQLiteDatabase db,String img) { db=this.getReadableDatabase(); Cursor cursor; cursor=db.query("record",new String[]{DETAIL,IMAGES,ITEMNO + " as _id"},SUBCATEGORY + "='" +img+"'",null,null,null,null); return cursor; }
android sqlite android-sqlite imageview
user5515672
source share