Parsing blog post - java

Let's say I am making a blog application about news. Whole idea is getting blog posts and showing them in application. I am parsing posts from RSS feed.
Every blog post has some amount of text,some pictures and a youtube video. I want to show everything exactly like in website. But all I can do is showing only text in text view:
<TextView
android:id="#+id/postContent"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="16dp"
android:textSize="18sp"
android:textColor="#color/postTextColor"/>
In post view activity:
final TextView mPostContent = (TextView) findViewById(R.id.postContent);
mPostContent.setText(Html.fromHtml(content).toString().replace("","").replace('\r', ' '));
This helps me to show text only. But as I mentioned blog post have more than one images. What should I do? Using webview is not a solution.

You can parse all the data using the RSS feeds and create a specific screen to display this parsed data the way you like.

It depends by the object format of your posts variable, maybe can it helps an adapter to a recyclerView and a CardView with the adapter class the with json or xml parser get the from the api response objects

Related

i want to add a floatActionButton on android studio with java

when i add the FloatingActionButton using graphique methode the android stuio appears to me this error "floatbutnID <com.google.android.material.floatingactionbutton.FloatingActionButton>: No speakable text present"
floatbutnID <com.google.android.material.floatingactionbutton.FloatingActionButton>: No speakable text present how could correct this
Speakable text is simply text that will be spoken by the system in phones for blind people. You can set it to "" if you don't need it.
This is the property for the speakable text
android:contentDescription="Your text"
You should look for information carefully before asking a question on Stack Overflow - it's in the rules of the forum. Please keep this in mind, otherwise you might get a bad reputation for duplicating questions.
I found the answer in 3 seconds in this question
if you are using xml, add android:contentDescription="content description" to the floatingActionButton tag. or in Java fab.setContentDescription(" content description") fab is the name of your floatingActionButton.
example
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="#+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:contentDescription="content description"/>
Alternatively in Java
FloatingActionButton fab = findViewById(R.id.fab);
fab.setContentDescription("content description");

No speakable text present at Android Studio

When adding a field for entering a number(Number widget), the error "No speakable text present at Android Studio" takes off
enter image description here
content_main.xml: enter image description here
activity_main.xml: enter image description here
The problem is you are missing content labeling for the view, you should add content description so the user could simply understand what data he should enter into the view
for example, if you want the user to enter the number of cookies he wants you should add a content description as seen below:
android:contentDescription="Enter How Much Cookies You Want"
You should also add an android:hint so the user would have it in front of them an example of the data you want inputted for example:
android:hint="e.g 5"
So your views XML code should look as follows
<EditText
android:id="#+id/editTextNumber2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="number"
android:minHeight="48dp"
android:contentDescription="Enter How Much Cookies You Want"
android:hint="e.g 8" />
The solution is simple you just need to add the text into the hint part.
search hint in search-bar ant type something in hint block.
and hit Enter.enter image description here
The problem is missing constraints. Any view you add in Constraint layout, you must set the margins otherwise you will get those errors and even if your app managed to run, your edit text will not be place properly.
Add this to your editText;
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
Let me know if it worked.
Remember you can twick this to your desired position.

How do I add someone's website link in my Android app?

I want to add some ticket booking links in my app. How do I add? I used webview that open the links in a browser. But is it correct?
You can simply use TextView to add link in your app.
<TextView
android:id="#+id/textView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/link_to_google"
/>
To make your string as link, add your string in String.xml..for example
<string name="link_to_google"><a href="http://www.google.com">Go to
Google</a></string>
and at last, call setMovementMethod on your textView
TextView textView =findViewById(R.id.textView);
textView.setMovementMethod(LinkMovementMethod.getInstance());

Equivalent of html img src in android

I am showing a link in an Android layout as follows:
<TextView
android:id="#+id/linkable_text”
android:layout_width="match_parent"
android:layout_height="match_parent"
android:autoLink="web"
/>
I also do: text.setMovementMethod(LinkMovementMethod.getInstance());
This works but I want to navigate to a different URL than the one displayed in my TextView (I add it dynamically).
I mean the link in the UI shows: file.html but when I press the link I would like to navigate to a url like: http://IP/path/file.html
How can I do that without having to show the whole URL in my TextView
Try this, and let me know what happen..
TextView textView =(TextView)findViewById(R.id.textView);
textView.setClickable(true);
textView.setMovementMethod(LinkMovementMethod.getInstance());
String text = "<a href='http://www.google.com'> Google </a>";
textView.setText(Html.fromHtml(text));

Displaying an Image Android

I am developing an Fitness App. My app will have different exercises like Push Ups and Sit Ups. Every exercise need to have an image to show to the user.
I have been thinking a while on what is a good way to solve this problem. But I don't think my solution below is good. Have you worked with images on Android for displaying images? Give me your solution on how you did it.
An exercise have a name but also images. The purpose is to display a specific Exercise with the images and exercise name.
My Exercise class looks like this right now:
I have thought of having the path to the image saved which I can have access when I need to show the image. I am uploading the images on the assets folder.
public class Exercise {
private String exerciseName;
private String exerciseSmallImagePath;
private String exerciseLargeImagePath;
public Exercise(String exerciseName, String exerciseSmallImagePath, String exerciseLargeImagePath){
this.exerciseName = exerciseName;
this.exerciseSmallImagePath = exerciseSmallImagePath;
this.exerciseLargeImagePath = exerciseLargeImagePath;
}
}
saving the path to the image-source is definitly a good approach. Have a look at ImageViews in order to display your image. There are two approaches to implement such an ImageView:
1: define it in your XML and set the image-source afterwards in your oncreate-method:
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:contentDescription="Some description" />
2: define your ImageView programmatically in your Activity:
ImageView imageView = new ImageView(this);
LinearLayout.LayoutParams vp =
new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT);
imageView.setLayoutParams(vp);
imageView.setImageResource(fetch your ID here);
someLinearLayout.addView(imageView);
I suppose you are familiar with how to create simple application in Android? If not, then you should get started with samples and reading up on Android developers guide
This article can give you good start in how to work with Images.
As for how you should accomplish this, I can only suggest one approach, the rest is upto your imagination.
Start with creating a fragment that has an image and a text below (or above if you like) it. You can then put this fragment where you want with new image and text.
Here is a rough idea
<LinearLayout (vertical orientation>
<Image ... />
<Text ... />
</LinearLayout>
Once the layout is in place you can set the image source at runtime.
A good way to display this information is to have steps which user can navigate using swiping (view pager).
Every page can have the above mentioned fragment that will show one step. This will result in cleaner, slide screen style guide.

Categories