Help please!
In my application I use Android-UiTableView ( thiagolocatelli / android-uitableview ) and AQuery ( androidquery / androidquery )
My task is to make the loading of data from json array and load image from URL.
Load a list without pictures I was able to:
jgall = json.getJSONArray("gall");
int z = 0;
for(int i = 0; i < jgall.length(); i++){
JSONObject c = jgall.getJSONObject(i);
tableView.addBasicItem(c.getString("name"), c.getString("place"));
}
I try to show a customized view and nothing happens
LayoutInflater mInflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
RelativeLayout view = (RelativeLayout) mInflater.inflate(R.layout.custom_view,null);
String iurl = c.getString("img");
aq.id(R.id.img).image(iurl, false, true);
ViewItem viewItem = new ViewItem(view);
tableView.addViewItem(viewItem);
Tell me it's real to make using Android-UiTableView? if so! how?
I have done this by modifying the library code myself.
I have added the following constructor at UITableView.java:
public void addBasicItem(Drawable drawable, String title, String summary) {
mItemList.add(new BasicItem(drawable, title, summary));
}
And the following at BasicItem.java:
public Drawable getDDrawable() {
return dDrawable;
}
public BasicItem(Drawable ddrawable, String _title, String _subtitle) {
this.dDrawable = ddrawable;
this.mTitle = _title;
this.mSubtitle = _subtitle;
}
And once again modified the setupBasicItem method at UITableView.java file:
((ImageView) view.findViewById(R.id.image)).setBackgroundDrawable(item.getDDrawable());
Finally, at your code add the following:
URL newurl = new URL("http://www.example.com/example.png");
Bitmap bmp = BitmapFactory.decodeStream(newurl.openConnection() .getInputStream());
Drawable drawable = new android.graphics.drawable.BitmapDrawable(getResources(),bmp);
tableView.addBasicItem(drawable, "Title", "SubTitle");
Hope it helps, cause it works for me.
Related
Glide won't load the images I have linked with the products on my recycler view. The images should be pulled from my PHP MySQL database. Not really sure what I did wrong. Please help
I've tried a few solutions I found on the web but none of them worked for me.
private String image;
The above is the string identifier from my product list
//loading the image
Glide.with(mCtx)
.load(product.getImage())
.into(holder.imageView);
holder.textViewPlateNumber.setText(product.getPlatenumber());
holder.textView1.setText(product.getMake());
holder.textView2.setText(product.getModel());
holder.textView3.setText(product.getYear());
holder.textViewName.setText(product.getName());
holder.textDate.setText(product.getDate());
holder.recyclerid.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
String platenumber = productList.get(position).getPlatenumber();
String make = productList.get(position).getMake();
String model = productList.get(position).getModel();
String year = productList.get(position).getYear();
String name = productList.get(position).getName();
String date = productList.get(position).getDate();
String vin = productList.get(position).getVin();
String displacement = productList.get(position).getDisplacement();
String fueltype = productList.get(position).getFueltype();
String transmission = productList.get(position).getTransmission();
String mileage = productList.get(position).getMileage();
String ownerorcompany =
productList.get(position).getOwnerorcompany();
String homeorcompanyaddress =
productList.get(position).getHomeorcompanyaddress();
String contactnumber =
productList.get(position).getContactnumber();
String emailaddress = productList.get(position).getEmailaddress();
String facebook = productList.get(position).getFacebook();
String image = productList.get(position).getImage();
The above is the code I used to show the images of each item off my adapter.
<de.hdodenhof.circleimageview.CircleImageView
android:id="#+id/imageView"
android:layout_width="0dp"
android:layout_height="0dp"
android:src="#drawable/car_avatar"
app:civ_border_color="#color/cta"
app:civ_border_width="2dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="#+id/guideline17"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
The above is how the image should be laid out in my xml file. The rest of the items saved on my php sql show up on the list except the images. Here is what my php file looks like:
$vehicle = array();
while ($row=mysqli_fetch_array($sql)) {
$temp = array();
$temp['id'] = $row['VehicleID'];
$temp['platenumber'] = $row['PlateNumber'];
$temp['make'] = $row['Make'];
$temp['model'] = $row['Model'];
$temp['year'] = $row['Year'];
$temp['name'] = $row['OwnerorCompany'];
$temp['date'] = $row['AddDate'];
$temp['image'] = $row['vehicleImage'];
$temp['vin'] = $row['Vin'];
$temp['displacement'] = $row['Displacement'];
$temp['fueltype'] = $row['FuelType'];
$temp['transmission'] = $row['Transmission'];
$temp['mileage'] = $row['Mileage'];
$temp['ownerorcompany'] = $row['OwnerorCompany'];
$temp['homeorcompanyaddress'] = $row['HomeorCompanyAddress'];
$temp['contactnumber'] = $row['ContactNumber'];
$temp['emailaddress'] = $row['EmailAddress'];
$temp['facebook'] = $row['FacebookID'];
array_push($vehicle, $temp);
}
echo json_encode($vehicle);
//}
?>
And this is how the images are saved on my database:
$photo = $_POST['photo'];
$id=uniqid();
$path = "vehicle_upload/$id.jpeg";
$finalpath = "http://192.168.0.10/widevalueautoInc
2/server/api/".$path;
When I run the app, all goes well except the images not showing up on the list. This is the java code I used to save the image and the size.
private void addVehicle(String stringImage) {
}
public String getStringImage(Bitmap bitmap){
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, byteArrayOutputStream);
byte[] imageByteArray = byteArrayOutputStream.toByteArray();
String encodedImage = Base64.encodeToString(imageByteArray,
Base64.DEFAULT);
return encodedImage;
}
}
remove circular imageview and use default image view, to use circle crop .. use Glide circle crop function....
Glide.with(context).load("dddd").apply(RequestOptions.circleCropTransform()).into(imageview);
Just make a common method as below in your utility class as below :
public static void setCircularImageToGlide(final Context context, final CircularImageView imageView, String imageUrl) {
Glide.with(context).load("" + imageUrl).asBitmap().placeholder(R.drawable.ic_photo_placeholder).transform(new CircleTransform(context)).into(new BitmapImageViewTarget(imageView) {
#Override
protected void setResource(Bitmap resource) {
RoundedBitmapDrawable circularBitmapDrawable =
RoundedBitmapDrawableFactory.create(context.getResources(), resource);
circularBitmapDrawable.setCircular(true);
imageView.setImageDrawable(circularBitmapDrawable);
}
});
}
I have passed CircularImageView as an argument to method single you are using CircularImageView instead of simple ImageView.
Call it as below wherever you need to set image in to your CircularImageView as below :
CommonUtil.setCircularImageToGlide(YOUR_CONTEXT, YOUR_CIRCULAR_IMAGE_VIEW, "" + YOUR_IMAGE_URL);
Am using below dependency :
implementation 'com.github.bumptech.glide:glide:3.7.0'
How to display image from sql database to listview in android xamarin using webservices and json?
public override View GetView(int position, View convertView, ViewGroup parent)
{
var item = objList[position];
if (convertView == null)
{
convertView = objActivity.LayoutInflater.Inflate(Resource.Layout.ContListViewHospName, null);
}
convertView.FindViewById<TextView>(Resource.Id.tvHospID).Text = item.HospID;
convertView.FindViewById<TextView>(Resource.Id.tvHospName).Text = item.HospName;
byte[] img = (byte[])item.HospLogo;
Bitmap bitmap = BitmapFactory.DecodeByteArray(item.HospLogo, 0, item.HospLogo.Length);
convertView.FindViewById<ImageView>(Resource.Id.imgLogo).SetImageBitmap(bitmap);
return convertView;
}
i store binary value in one string variable then i use json to transfer values to my cs file in my android project
Your store binary value in one string should looks like this: "iVBORw0KGgoAAAANSUhEUgAAAgAAAAIACAYAAAD0eNT6AAAABHNCSVQICAgIfAhkiAAAIABJREFUeJzsvfd33EiW7/mJgEtHb0WKFGWqSuW96epqM9P9+s30mZ/2j33n7O7Zt/Nme8zr6emu6i5fk........"
That is base64 bytes. You can not just use (byte[]) to convert the string to byte[]:
you need to use System.Convert.FromBase64String() function.
//The string is download form server in the json file
string myBytes = "iVBORw0KGgoAAAANSUhEUgAAAgAAAAIACAYAAAD0eNT6AAAABHNCSVQICAgIfAhkiAAAIABJREFUeJzsvfd33EiW7/mJgEtHb0WKFGWqS........"
byte[] decByte3 = System.Convert.FromBase64String(myBytes);
And then convert the bytes to image:
public Bitmap Bytes2Bimap(byte[] b)
{
if (b.Length != 0)
{
return BitmapFactory.DecodeByteArray(b, 0, b.Length);
}
else
{
return null;
}
}
and convert the bitmap to drawable :
Bitmap myIcon = Bytes2Bimap(decByte3);
Drawable myIconD = new BitmapDrawable(myIcon);
imageView1.Background = myIconD;
May be your image is too big try to scale it, like here
Also make sure you have set proper dimension in your layout like width and height.
I get
Caused by: android.content.res.Resources$NotFoundException: Resource ID #0x7f060000
when I try to load a bitmap from a resource in my res/drawable folder (even intelliJ auto-complete finds them) like so:
public Sprite(int resource, int numberOfFrames){
BitmapRegionDecoder spriteSheet = null;
try {
InputStream is = Resources.getSystem().openRawResource(+resource);
spriteSheet = BitmapRegionDecoder.newInstance(is, false);
} catch (IOException ioexc){
ioexc.printStackTrace();
}
timer = 0;
this.numberOfFrames = numberOfFrames;
frames = new Bitmap[numberOfFrames];
for (int i = 0; i < numberOfFrames; i++) {
frames[i] = spriteSheet.decodeRegion(new Rect(i*32, 0, (i*32)+32, 32), null);
}
and I pass the resource only 2 times:
public class PlayerSprite extends Sprite {
private boolean isHitting;
private int timer;
public PlayerSprite() {
super(R.drawable.player_sprite_sheet, 3);
timer = 0;
}
//...more core...//
}
and here:
sprite = new Sprite(R.drawable.ball_sprite, 7);
Here you can see my directory
Resources.getSystem() is the problem in your case. It returns a global shared Resources object but not the one of the application. You should use Context.getResource() instead, which returns
a resources instance for the application's package
here you can find the documentation for Context.getResource() and for Resources.getSystem()
I've to read a stream from a rss feed on an Android application.
All work fine, but i'm not able to get the complete url, from the tag, because it's a selfclosed tag
somethings like
This's the xml page (i can't edit it) Xml source page
and this is the code to populate to create the single objet that I need
String titolo, descrizione, descrizione_breve, img, data, icona;
Notizia SitoDaAggiungere;
for (int i = 0; i < nodi.getLength(); i++) {
Node nodoItem = nodi.item(i);
if (nodoItem.getNodeType() == Node.ELEMENT_NODE) {
Element elemento = (Element) nodoItem;
titolo = elemento.getElementsByTagName("title").item(0).getTextContent();
descrizione_breve = elemento.getElementsByTagName("summary").item(0).getTextContent();
descrizione = elemento.getElementsByTagName("content").item(0).getTextContent();
img = elemento.getElementsByTagName("pic1").item(0).getTextContent();
data = elemento.getElementsByTagName("updated").item(0).getTextContent();
icona = elemento.getElementsByTagName("pic").item(0).getTextContent();
String link_sito = elemento.getElementsByTagName("link").item(0).getTextContent(); // <-- no error, but an empty string
SitoDaAggiungere = new Notizia(titolo, descrizione, descrizione_breve, data, img, icona, link_sito);
InserisciSito(SitoDaAggiungere);
}
}
Someone can help me?
thank's a lot!
finally I do it!!!
this's the code to get the url
String link_sito = elemento.getElementsByTagName("link").item(0).getAttributes().item(0).getTextContent();
now I simply use it to create the new objet
I am new to Android, I am developing an app, where in I search the youtube using the
....
YouTubeService service = new YouTubeService('blah','blah')
....
VideoFeed videoFeed = service.query(query, VideoFeed.class);
List<VideoEntry> videos = videoFeed.getEntries();
YouTubeMediaGroup mediaGroup = videoEntry.getMediaGroup();
String webPlayerUrl = mediaGroup.getPlayer().getUrl();
......
ytv.setWebPlayerUrl(webPlayerUrl);
.....
List<String> thumbnails = new LinkedList<String>();
for (MediaThumbnail mediaThumbnail : mediaGroup.getThumbnails()) {
thumbnails.add(mediaThumbnail.getUrl());
}
....
In the Adapter, I used this
mWebView.loadUrl(torvideo.getWebPlayerUrl());
But I get a full screen youtube image in the webview and a scroll able list of similar videos.
However What I want is a thumbnail which looks similar to youtube search result (Small Image, title of the video and few more details.
Can you please suggest me, which view or a sample code, so that I can use the thumbnails list I got it from mediagroup object to display in my app?
Edit/Update:
I have used
public class ResultViewAdapter extends BaseAdapter {
........
#Override
public View getView(int position, View convertView, ViewGroup parent) {
View row = convertView;
if (row == null) {
final LayoutInflater li = (LayoutInflater) myContext
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
row = li.inflate(R.layout.activity_result_list, null);
}
TORYouTubeVideo torvideo = (TORYouTubeVideo) getItem(position);
TextView textView = (TextView) row.findViewById(R.id.textView1);
textView.setText(torvideo.getVideoTitle());
InputStream is = (InputStream) new URL(torvideo.getThumbnails().get(0)).getContent();
Drawable d = Drawable.createFromStream(is, "src name");
ImageView imageView = (ImageView) row.findViewById(R.id.imageView1);
imageView.setImageDrawable(d);
return row;
}
But still I cannot see the images in my list view and Only see an empty scrollable list
Thanks
Answering my question again!!
Moved this part
InputStream is = (InputStream) new URL(torvideo.getThumbnails().get(0)).getContent();
Drawable d = Drawable.createFromStream(is, "src name");
To the same async task where my youtube query is happening and I am able to see the image now!
(It was the issue with mainThread)
Looks like long way to go with Android!! :P
Thanks