Two part query about creating a read-only Android app - java

I am a noob and have no one to help me so please forgive my ignorance.
1) I have three menus on main activity (three buttons like read, about and info). I used intent for one of the buttons. But how do I redirect the other two buttons to specific activities (view only)
public void onClick(View view) {
Intent i = new Intent(this, Main2Activity.class);
startActivity(i);
}
2) What widget should I use to display a page of article within an activity? I have used plain text but unable to format it.
Thanks for the kind help.

You need to implement an onclick listener on each of the buttons.
An example of how to implement it is available here.
It depends on what format the article is. If it is already in HTML format. You may use a WebView widget.
FYI: You can format a normal TextView, but that's probably a little more advanced and better left alone for now.

You should have no problem in using same intent to redirect.
Try to host that article online, using css and html and then just link that webpage by using web view in your activity.

Related

How to use dynamic buttons with array data

I am still working on my first android app and hope you can help me once more. I use the YouTube API to get all the content from my channel and create the following list:
Now my problem is I do not know how I can tell the buttons in the middle of each thumbnail to start the according video. I have the correct video ID for each element (provided in a textview on the right during troubleshooting...) but when I try to connect this information to the button onclick method it will just use the first textview content on the screen, so it is always just opening the first video => for every single button.
public void jumpin(View view) {
TextView textViewHelper = (TextView) findViewById(R.id.videoIdTester);
String textViewHelperString = textViewHelper.getText().toString();
Intent intent = YouTubeStandalonePlayer.createVideoIntent(this, API_KEY, textViewHelperString);
startActivity(intent);
}
My basic problem is that the buttons are not filled with the video ID information like the textviews for example. The buttons are just created and I call the onclick method which needs the video id then which is not reachable from my perspective as soon as the list is created.
I think this is by far too complicated at the moment but I have no plan how to solve that. I can provide more code if you need it but I think this problem is more about button and api/array behaviour in general.
Anwered by myself, using an onitemclick listener instead of the buttons ...

How can I animate the opening of a secondary android activity? as on playstore news

Although I do know how to open another activity quite easily, using intent like the below:
Intent intent = new Intent(first.this, second.class); intent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
intent.putExtra("selectedApp", ApplicationTitle.getText());
startActivity(intent);
When you use the android application "PlayStore News", when you select a news item rather than just being redirected to another activity. An animation occurs, where in the change between several small cards to one large occurs.
How can I accomplish this?
http://www.mysamplecode.com/2013/02/android-animation-switching-activity.html
There is a method
overridePendingTransition(R.anim.push_up_in, R.anim.push_up_out);
You might want to check out https://developer.android.com/training/material/animations.html#Transitions
This explains how to define custom transitions between activities. In particular, you may be interested in shared element transitions. I'd be more specific, but its a fairly broad question
Check this sample code for animation while switching activities in android.
http://android-er.blogspot.in/2013/04/custom-animation-while-switching.html
http://www.mysamplecode.com/2013/02/android-animation-switching-activity.html

Android App Development : How do change content on screen depending on event

Just starting out developing some android apps. Coming from a web development background I'm wondering if the idea behind changing whats displayed on screen is similar to linking html files.
Say I had a button that once clicked would then display a completely new page, button gone and completely new content in its place. I had thought at first that this was done just by having conditional statements in the main activity class. But I don't see how this would work with the xml layout file.
So I have come to the conclusion that you have to define multiple xml files and switch between them using logic in the main class.
If this is correct whats the best way to go about this, and if not could some suggest how this is achieved normally?
Thanks.
I think it wise to follow the following tutorial: http://developer.android.com/training/basics/firstapp/index.html
Have you tried visiting Android developers' website?.The solution to your question can be obtained taking the Android training module in that website. You have said you want to go to a new page, you can use Activities here.
Let me explain you this in simple terms.
In Android for every page(Activity) you need to make a separate xml file. for example main_activity.xml.
And for each page(Activity) there is a java class. For ex MainActivity.java. This class may contain event handling and business logic part.
Now let's go to your question about switching between multiple pages.
Suppose you have 2 activities: MainActivity and SecondActivity.
Now in MainActivity you have a button then you set its onClick attribute to its event handling method. This can be done in xml file.
android:onClick="goToSecond"
Now in MainActivity.java you need to create a method which looks like this.
public void goToSecond(View v)
{
Intent i=new Intent(MainActivity.this,SecondActivity.class);
startActivity(i);
}
This is a code snippet for switching to second activity.
And I also agree with other answers that you should check out developers.android.com
Hope it helps.
There is no need to switch between the XML files for portrait and landscape mode. Android does that for you. If you are writing an app that uses both orientation, then you have to write separate layout files and keep them in layout(for portrait), layout-land(for landscape) folders. This is not at all necessary if your design looks same in both orientation.

programming an android app - where to start

I have been looking all over the internet and i found some good guides for programing in android but i still dont fully understand what exactly is going on with this thing
i thought this would be like programing a java program but its very different.. there are lots of xml files and there is this thing called "activity" and an "intent" of which i dont understand how they work.. same with the way of displaying things..there is this xml file that designs the way the app looks but when you i used this code:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Get the message from the intent
Intent intent = getIntent();
String message = intent.getStringExtra(FirsttimeActivity.EXTRA_MESSAGE);
// Create the text view
TextView textView = new TextView(this);
textView.setTextSize(40);
textView.setText(message);
setContentView(textView);
}
the text box that was there before disappeared and a normal text appeared instead.. what just happand here? how do i replace the text with something else after that? how do i go back to the normal view?
so my qoustions are as follows:
what does an "activity" mean? whats the parallel in a normal java project?
whats an intent and how does it work?
how do i control the display? how come it changed when i entered that code?
thanx
An Activity is an essential part of Android development. Its basically a class which you can use to represent any number of UIs. The onCreate method is not a constructor, but is called as soon as the Activity is started, so initializing your information in there is a good idea. The program knows which Activity it is starting with within your android manifest file with the line of code
<category android:name="android.intent.category.LAUNCHER" />
There is no real parallel to a 'normal' java project. An intent is used to pass information from Activity to Activity. The best way to learn about Intents is to read about them here :
http://developer.android.com/reference/android/content/Intent.html
The actual visual part of what you see, is controlled in the XML files which are located in the /res/layout/ folder within your project.
This is all very basic information that you should know before coming here. A more detailed guide and tutorial can be found the Android developer's site. Go through the tutorials and guides and learn as much as you can before looking anywhere else or asking on Stack Exchange. I've provided some basic answers here, but you can find better details on the site I linked earlier.
In basest terms, an Activity is a specific screen and is the building block of the typical Android application. Each screen that you see in an Android application such as the settings screen or main application screen is a single Activity.
XML files are used to design the layouts of each Activity that requires a graphical interface. When you used
TextView textView = new TextView(this);
textView.setTextSize(40);
textView.setText(message);
You created an entirely new TextView widget. To link to a widget that has been described in the XML file, you call the findViewById(int id) method.
An Intent is how an Android application passes information between Activities and launches new Activities.
If you visit http://developer.android.com you can find all the info you need.
Learn programming Android requires some studying. The official developer site is the best point to start.

Determining when to use which Android components?

Firstly, I'm new to Android (so I apologize if this question is ignorant) but have some experience in Java. I have been reading a book on Android and remain slightly confused about the basic components (activities, intent, content providers, and broadcast receivers).
I have a few java classes that I'm wanting to convert over to Android but I'm not sure what type of components they should be.
If a class does simple conversions, should that be an intent?
Or, if a class draws, should it be an activity?
I'm just looking for someone who can explain the components a bit better than the references at android and perhaps give some good examples of each component.
I think you're confused about some of the terminology. An activity is what the user interacts with (displays the content, contains the listeners for buttons, etc.) So when you launch an app and see something on the screen, an Activity is what draws all the buttons/components on screen and contains the code for user interaction. An intent is kind of a way to tell activity to launch something else. For example, if you were on your main activity, and wanted to change the Activity when the user clicked something, you would create and start an intent specifying that:
Intent intent = new Intent(CurrentActivity.this, NextActivity.class);
startActivity(intent);
Read this basic tutorial. It should be somewhat clearer than the official docs.
http://androiddevelopertips.com/activity/understanding-activities-in-android.html

Categories

Resources