Upload an image to an Android Studio Recyclerview, from a directory path - retrofit2

First of all I appreciate your attention and the help you can give me. I have a problem with loading an image being hosted in a server directory. I am generating the view from recyclerview, I am using Retrofit library.
The response generated by the WS is the following after a query for the ID:
[
{
"id": 3,
"name": "hello",
"detail": "sss",
"path_image": "images/hello.jpg"
}
]
The other fields return me successfully with the following code from the RecyclerAdpater in Android studio:
#Override
public void onBindViewHolder(#NonNull final MyViewholder holder, final int position)
{
holder.txtId.setText(myimages.get(position).getId());
holder.txtMsj.setText(myimages.get(position).getName());
holder.txtDE.setText(myimages.get(position).getDetail());
}
I will also place the table of the BD to which I am addressing the data mentioning also that I have generated my get & set in AS of these fields:
create TABLE images2 (
id int NOT NULL identity primary key,
name varchar(100) NULL,
detail varchar(100) NULL,
image varchar(max),
path_image varchar(50) NULL
)
As I mentioned earlier, the image is being stored in a directory with the name and extension of said image inserted from the same application, however after several unsuccessful investigations of the case, I still have the problem of visualizing said image. I would be very grateful if there is any tool or line of code that would help me complete the objective. Thanks in advance.

I solved it using the Glide library.
#Override
public void onBindViewHolder(#NonNull final MyViewholder holder, final int position)
{
holder.txtId.setText(myimages.get(position).getId());
holder.txtMsj.setText(myimages.get(position).getName());
holder.txtDE.setText(myimages.get(position).getDetail());
Glide.with(context).load("MY_URL_IMAGES/"+myimages.get(position).getPath_image()).into(holder.ivPec);
}

Related

Enable android studio smart variable name on implementation

I am following a course on Udacity on android development. When I try something like this with auto complete:
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
}
});
you can see that the primitive variable got the names i, and j. In this video, I believe android studio automatically gave the int variable the name "position". Do I need to enable this in android studio's settings, or is did the developer in the video just manually changed the name?
Much likely he changed it on his own. That's because the method of the AdapterView.Class defines the OnItemClickListener interface as follows:
public static interface OnItemClickListener {
void onItemClick(
android.widget.AdapterView<?> adapterView,
android.view.View view,
int i, // <-- position
long l);
}
As you can see, the position is named i that's why the Auto-Completion names it this way.

How to create a table view dyanamically in javafx?

In my app i have some sets of command which is unknown in the beginning. These command usually send some data .
I want to push all executing command to table view of javafx.Currently i could able to do that using a observable arraylist.Currently i am updating the arraylist whenever new command is coming.but i want to display each command in different table view.For that i want to create the table view dynamically a/c to the command
Exp- suppose i have 3 commands command 1 command 2 command 3
than i should able to create table according to the command that is executing if command 1 comes then i should create table and display its data in that .If command 2 comes than the application should create 2nd table and so on.
Any help on this will be appreciated .Thanks in advance...
for creating dynamic tables in javafx...first you need to a Java file with setter and getter properties and main final where you access it.
below examples show how its work...
User.java
public class User
{
int id;
String name;
public int getId() {
return id;
}
public void setId(int id) {
this.id= id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
now you can can use this class in your main file
Main.java
set variables
public static TableView<User> table;
private TableColumn<User, Integer> ColId;
private TableColumn<User, String> ColName;
ObservationList objlst = FXCollections.observableArrayList();
now you have to set Columns property for add data into them.
colId.setCellValueFactory(new PropertyValueFactory<User,Integer>("id"));
colName.setCellValueFactory(new PropertyValueFactory<CustomerDetailDO,String>("name"));
now you can make two functions for fill and clean table
public void FillTable()
{
User ab = new User();
objlist.add(ab.setId(1));
objlist.add(ab.setName("demo"));
table.setItems(objlist);
}
and for clean table
public void CleanTable()
{
objlist.clear();
table.setItems(objlist)
}
use of these functions you can make updates and delete data into table
I hope this will work for you..

Saving Monotouch.Dialog element values to a file

I'm using MonoTouch for developing my iPhone application. I want to use Monotouch. Dialog for showing some data to a client and let them change data and then save them to the file again.
My code is something like the code of Xamarin tutorials:
(Orginal Sample link)
public enum Category
{
Travel,
Lodging,
Books
}
public class ExpesObject{
public string name;
}
public class Expense
{
[Section("Expense Entry")]
[Entry("Enter expense name")]
public string Name;
[Section("Expense Details")]
[Caption("Description")]
[Entry]
public string Details;
[Checkbox]
public bool IsApproved = true;
[Caption("Category")]
public Category ExpenseCategory;
}
It is representing the TableView so good.
But the question is this, how we can save the data of this elements and the use them in other class of application? What is the best way for doing this?
I guess that we can save data to a file when user changed them. but how we can detect when the user change the data?
In the example you have shown, you are using the simple Reflection API for Monotouch.Dialog. While this is nice and easy, it really limits what you can do. I would suggest learning to use the Elements API seen here (http://docs.xamarin.com/guides/ios/user_interface/monotouch.dialog/elements_api_walkthrough) of Monotouch.Dialog which will give you so much more control over each item in the table, and be able to detect the changes, etc.
Each of the table cells (e.g. Name is a cell, which you can edit) have actions/events for when certain things happen, like text being changed.
For example, the above screen can be made with the elements API doing the following.
public class ExpenseViewController : DialogViewController
{
EntryElement nameEntry;
public ExpenseViewController() : base(null, true)
{
Root = CreateRootElement();
// Here is where you can handle text changing
nameEntry.Changed += (sender, e) => {
SaveEntryData(); // Make your own method of saving info.
};
}
void CreateRootElement(){
return new RootElement("Expense Form"){
new Section("Expense Entry"){
(nameEntry = new EntryElement("Name", "Enter expense name", "", false))
},
new Section("Expense Details"){
new EntryElement("Description", "", "", false),
new BooleanElement("Approved", false, ""),
new RootElement("Category", new Group("Categories")){
new CheckboxElement("Travel", true, "Categories"),
new CheckboxElement("Personal", false, "Categories"),
new CheckboxElement("Other", false, "Categories")
}
}
};
}
void SaveEntryData(){
// Implement some method for saving data. e.g. to file, or to a SQLite database.
}
}
Consider these areas to get started using the Elements API:
Source: https://github.com/migueldeicaza/MonoTouch.Dialog
MT.D intro: http://docs.xamarin.com/guides/ios/user_interface/monotouch.dialog
MT.D Elements walkthrough: http://docs.xamarin.com/guides/ios/user_interface/monotouch.dialog/elements_api_walkthrough

LWUIT HtmlComponent

I've an Html String:
String html="<p><img border=\"1\" align=\"left\" width=\"150\" vspace=\"2\" hspace=\"2\" height=\"159\" src=/"tmdbuserfiles/ntr-vv-vinayak-pics.jpg\" alt=\"Prithvi II, ballistic missile, DRDO, armed forces,Chandipur, Balasore district, Odisha State\" />The Strategic Forces Command of the armed forces successfully flight-tested the surface-to-surface Prithvi II missile from Chandipur in Balasore </P>";
I want to display the text as well as Image on my LWUIT Form Screen,For my Requirement I've used the below code:
public class LwuitMidlet extends MIDlet {
public void startApp() {
Display.init(this);
Form f = new Form("Hello, LWUIT!");
String html="<p><img border=\"1\" align=\"left\" width=\"150\" vspace=\"2\" hspace=\"2\" height=\"159\" src=www.teluguone.com/tmdbuserfiles/ntr-vv-vinayak-pics.jpg\" alt=\"Prithvi II, ballistic missile, DRDO, armed forces,Chandipur, Balasore district, Odisha State\" />The Strategic Forces Command of the armed forces successfully flight-tested the surface-to-surface Prithvi II missile from Chandipur in Balasore </P>";
HTMLComponent com=new HTMLComponent();
com.setPreferredSize(new Dimension(300,300));
com.setHTML(html, null, null, false);
com.setShowImages(true);
//com.setHTML(image, null, null, false);
f.addComponent(com);
f.show();
}
public void pauseApp() {
}
public void destroyApp(boolean unconditional) {
}
}
If i use the above code,I'm able to display only the text,but i'm not able to display the image,I've tested my app on Nokia SDK 2.O and SDK 3.0.5
can any one help me?
You need to have the full HTML code not just a snippet. The HTML, body etc.
Your src attribute on the img tag is missing the (") character at the beginning. I have not tried but this can be it.
Have you try using
com.setBodyText(html);
instead
com.setHTML(html, null, null, false);
and. I am using HttpRequestHandler implementation from LWUIT example application (you can get the sample apps: LWUITBrowser), instead of DefaultRequestHandler or null.
HttpRequestHandler handler = new HttpRequestHandler();
HTMLComponent com = new HTMLComponent(handler);
Hope it helps.

ContentManager.Create does nothing

I am trying to build a service in Orchard that allows me to create content through a custom form on a page. The service and the content type definitions look fine to me, but somehow, eventhough I don't get any errors or other signs in the Orchard log files, creating new content using the IContentManager does nothing for me.
Parts involved
The controller accepting the form values
[HttpPost]
public ActionResult Create(CreateSopViewModel viewModel)
{
if(!ModelState.IsValid)
{
var shape = _shape.CreateContent();
shape.Header = _shape.Parts_Title(Title: "New item");
// Add the original fields to the shape.
shape.Title = viewModel.Title;
shape.Description = viewModel.Description;
shape.InitialComments = viewModel.InitialComments;
return new ShapeResult(this, shape);
}
// Store the new procedure in the database
_service.CreateContentItem(
viewModel.Title,viewModel.Description,viewModel.InitialComments);
// Redirect the user back to the homepage.
return Redirect("~/");
}
The service that contains the CreateContentItem method:
public void CreateContentItem(string title, string description, string initialComments)
{
// Initialize a new content item based on the SOP type
var customPart = _services.ContentManager.New<MyCustomPart>("CustomContentType");
customPart.Description = description;
customPart.Identifier = BuildIdentifier(title);
customPart.ContentItem.As<TitlePart>().Title = title;
_services.ContentManager.Create(customPart.ContentItem);
}
The content part + record
public class MyCustomPart: ContentPart<MyCustomPartRecord>
{
[Required]
public string Identifier
{
get { return Record.Identifier; }
set { Record.Identifier = value; }
}
[Required]
public string Description
{
get { return Record.Description; }
set { Record.Description = value; }
}
}
public class MyCustomPartRecord: ContentPartRecord
{
public virtual string Identifier { get; set; }
public virtual string Description { get; set; }
}
The migration
SchemaBuilder.CreateTable(typeof(MyCustomPartRecord).Name, table => table
.ContentPartRecord()
.Column<string>("Description")
.Column<string>("Identifier"));
ContentDefinitionManager.AlterPartDefinition("StandardOperationalProcedurePart", builder => builder
.Attachable(true));
ContentDefinitionManager.AlterTypeDefinition("CustomContentType", builder => builder
.DisplayedAs("Custom Content Type")
.WithPart("TitlePart")
.WithPart("MyCustomPart")
.Creatable(true));
Question
Again, I don't get any errors, not in the log and not in Visual Studio. However, my new content item doesn't get created or at least, I can't see it in the admin section of the site under Content.
What is going on and how can I debug this behavior?
I had a similar problem, which was solved when I used the overloaded Create method taking a VersionOptions enum value:
content.Create(customPart.ContentItem, VersionOptions.Published);
This should work even if the content item is not creatable, as mine isn't.
I had a similar issue. In my case the item did appear eventually, but not right away.
The solution for me was to do:
_contentManager.Flush();
I was having this issue, in my case it was that I actually had an error in the database (trying to put 100+ characters into a field that would only hold 100!).
I found the error I was getting (null id in Orchard.Indexing.Models.IndexingTaskRecord entry (don't flush the Session after an exception occurs) ), actually masked the issue. I had to go hunt in the logs to find the real problem.
So anyway, my advice is if you see that contentmanager.create seems to be doing nothing, and any errors don't seem to help, check the logs carefully. They can be found in the logs sub-folder of the appdata folder in the main Orchard.Web project. Because as I've found in the last 48 hours, often the answer is there.

Resources