New to Forum, New to Android - Android Studio

Hey ladies and gents,
I'm new to your forums, seems it will be a helpful resource as I undertake this new project. I'm not new to programming, but i'm rusty. About 20 years ago I started with Qbasic, in high school i moved on to Visual Studio and C++. But I have been out of it for awhile now.
I started learning a little python to help my dad with his own program. But Decided I wanted to use Android Studio for my own. I have already started looking into tutorials, but have yet to see some information I am looking for. ( Or just don't recognize due to inexperience )
Traditionally, whats best to use for a multiscreen App? I am currently running windows in Fragments. I have a sidescreen that pops out with a menu button (works), windows slide out with options ( works ), when you select the option the window slides away (works) and it brings up the fragment so you can fill in forms (works.)
Inside my Fragments java file I have this
public class ac extends Fragment {
private EditText od_input;
private EditText sp_input;
private EditText hp_input;
private EditText sl_input;
private EditText hl_input;
private EditText return_input;
private EditText vent_input;
private TextView diag_output;
// TODO: Rename parameter arguments, choose names that match
// the fragment initialization parameters, e.g. ARG_ITEM_NUMBER
private static final String ARG_PARAM1 = "param1";
private static final String ARG_PARAM2 = "param2";
// TODO: Rename and change types of parameters
private String mParam1;
private String mParam2;
private OnFragmentInteractionListener mListener;
public ac() {
// Required empty public constructor
}
/**
* Use this factory method to create a new instance of
* this fragment using the provided parameters.
*
* @param param1 Parameter 1.
* @param param2 Parameter 2.
* @return A new instance of fragment ac.
*/
// TODO: Rename and change types and number of parameters
public static ac newInstance(String param1, String param2) {
ac fragment = new ac();
Bundle args = new Bundle();
args.putString(ARG_PARAM1, param1);
args.putString(ARG_PARAM2, param2);
fragment.setArguments(args);
return fragment;
}
EditText odtext;
EditText idtext;
EditText sptext;
EditText hptext;
EditText sltext;
EditText hltext;
EditText returntext;
EditText venttext;
@override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (getArguments() != null) {
mParam1 = getArguments().getString(ARG_PARAM1);
mParam2 = getArguments().getString(ARG_PARAM2);
}
}
@override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_ac, container, false);
// NOTE : We are calling the onFragmentInteraction() declared in the MainActivity
// ie we are sending "Fragment 1" as title parameter when fragment1 is activated
if (mListener != null) {
mListener.onFragmentInteraction("Air Conditioning");
}
// Here we will can create click listners etc for all the gui elements on the fragment.
// For eg: Button btn1= (Button) view.findViewById(R.id.frag1_btn1);
// btn1.setOnclickListener(...
//odtext = view.findViewById(R.id.odtext);
//idtext = (EditText) findViewById(R.id.idtext);
//sptext = view.findViewById(R.id.sptext);
//hptext = view.findViewById(R.id.hptext);
//sltext = view. findViewById(R.id.sltext);
//hltext = view.findViewById(R.id.hltext);
//returntext = view.findViewById(R.id.returntext);
//venttext = view.findViewById(R.id.venttext);
//TextView diagtext = view.findViewById(R.id.diagtext);
//diagtext.setText((CharSequence) odtext);
return view;
}
@override
public void onAttach(Context context) {
super.onAttach(context);
if (context instanceof OnFragmentInteractionListener) {
mListener = (OnFragmentInteractionListener) context;
} else {
throw new RuntimeException(context.toString()
+ " must implement OnFragmentInteractionListener");
}
}
@override
public void onDetach() {
super.onDetach();
mListener = null;
}
/**
* This interface must be implemented by activities that contain this
* fragment to allow an interaction in this fragment to be communicated
* to the activity and potentially other fragments contained in that
* activity.
* <p>
* See the Android Training lesson <a href=
* "http://developer.android.com/training/basics/fragments/communicating.html"
* >Communicating with Other Fragments</a> for more information.
*/
public interface OnFragmentInteractionListener {
// NOTE : We changed the Uri to String.
void onFragmentInteraction(String title);
}
}
Firstly, yes there is a lot of useless crapification going on. Was running different experiments and have not fully cleaned up yet.
But, as people type in the field I want to capture the inputs. Does this require a Listener? Can you capture as they type or do I need a button (Really, Really don't want a button)?
Also, I am unfamiliar with the layout of the java.
Oncreate is when the program boots up?
onCreateview is when the Fragment is booted up?
onattach is when the main activity is associated?
ondetach is when its associated from activity?
I don't fully understand yet where the best place is to add stuff, would it be after onattach?
Thanks for pointing me in the right directions guys.
Chris W.

Related

[Q] How to update a textView every second.

I have a textview that shows your amount of money and i would like the ui to update every second to visually show how much money you have in real time. Would i be able to accomplish this with a timer?, and if so what would it look like.
Hello,
You should do inside your class, outside of any method:
Code:
TextView tv;
String calculatedString;
MyAsyncTask mAsync = null;
Timer timer = null;
TimerTask task = null;
private class MyAsyncTask extends AsyncTask<String, Void, String> {
public MyAsyncTask(){
}
@Override
protected String doInBackground(String... params) {
//Background operation in a separate thread
//Write here your code to run in the background thread
//calculate here whatever you like
calculatedString = ....;
return null;
}
@Override
protected void onPostExecute(String result) {
//Called on Main UI Thread. Executed after the Background operation, allows you to have access to the UI
tv.setText(calculatedString);
}
@Override
protected void onPreExecute() {
//Called on Main UI Thread. Executed before the Background operation, allows you to have access to the UI
}
}
inside the onCreate after super and setContentView:
Code:
tv = (TextView) findViewById(R.id.tv); //your tv id here
final Handler handler = new Handler();
timer = new Timer();
task = new TimerTask() {
@Override
public void run() {
handler.post(new Runnable() {
public void run() {
MyAsyncTask mAsync = new MyAsyncTask();
mAsync.execute();
}
});
}
};
timer.schedule(task, 0, 1000); //Every 1 second
If you still need help, feel free to ask
I have attached 2 screenshots showing the errors i was given after inputting. Any idea how to fix this?
mmdeveloper10 said:
Hello,
You should do inside your class, outside of any method:
Code:
TextView tv;
String calculatedString;
MyAsyncTask mAsync = null;
Timer timer = null;
TimerTask task = null;
private class MyAsyncTask extends AsyncTask<String, Void, String> {
public MyAsyncTask(){
}
@Override
protected String doInBackground(String... params) {
//Background operation in a separate thread
//Write here your code to run in the background thread
//calculate here whatever you like
calculatedString = ....;
return null;
}
@Override
protected void onPostExecute(String result) {
//Called on Main UI Thread. Executed after the Background operation, allows you to have access to the UI
tv.setText(calculatedString);
}
@Override
protected void onPreExecute() {
//Called on Main UI Thread. Executed before the Background operation, allows you to have access to the UI
}
}
inside the onCreate after super and setContentView:
Code:
tv = (TextView) findViewById(R.id.tv); //your tv id here
final Handler handler = new Handler();
timer = new Timer();
task = new TimerTask() {
@Override
public void run() {
handler.post(new Runnable() {
public void run() {
MyAsyncTask mAsync = new MyAsyncTask();
mAsync.execute();
}
});
}
};
timer.schedule(task, 0, 1000); //Every 1 second
If you still need help, feel free to ask
Click to expand...
Click to collapse
Hello,
For the first image:
You have to import the AsyncTask.
add this
Code:
import android.os.AsyncTask;
with the other imports in your java file.
For your second image:
You haven't wrote the line
Code:
setContentView(R.layout.activity_main);
under your super.onCreate(savedInstanceState); and then the code I said above (I said that on my post )
inside onCreate, where activity_main is your xml layout. And you should have inside that layout, a TextView with an id "tv" (or whatever you like)
and then:
Code:
tv = (TextView) findViewById(R.id.tv); //your tv id here
R.id.tv must much the id you have in your layout. Replace it with the actual id of your TextView. If your id is "tv", write R.id.tv, if it is "mytv" write R.id.mytv. ( I said that on my post also)
Can you show your layout file? (XML - your activity_main.xml). You said that you have a TextView Where is your TextView?
Ok I fixed the problems stated and now only have these two errors remaining
mmdeveloper10 said:
Hello,
For the first image:
You have to import the AsyncTask.
add this
Code:
import android.os.AsyncTask;
with the other imports in your java file.
For your second image:
You haven't wrote the line
Code:
setContentView(R.layout.activity_main);
under your super.onCreate(savedInstanceState); and then the code I said above (I said that on my post )
inside onCreate, where activity_main is your xml layout. And you should have inside that layout, a TextView with an id "tv" (or whatever you like)
and then:
Code:
tv = (TextView) findViewById(R.id.tv); //your tv id here
R.id.tv must much the id you have in your layout. Replace it with the actual id of your TextView. If your id is "tv", write R.id.tv, if it is "mytv" write R.id.mytv. ( I said that on my post also)
Can you show your layout file? (XML - your activity_main.xml). You said that you have a TextView Where is your TextView?
Click to expand...
Click to collapse
Have you imported this?
Code:
import java.util.logging.Handler;
If so, change it to
Code:
import android.os.Handler;
Im not at the computer but I think that should solve my issue I will keep you updated
Sent from my HTC6525LVW using XDA Free mobile app
Hey thanks so much its working perfectly now :good:

The Wrong Activity Shows Up Android Studio

Can anybody help me. I have developed a quiz app. At the end of the quiz the result activity must show up but the scores activity shows up. The scores activity only shows up when the scores button is selected on the MainActivity.
Quiz.java
Code:
package app.mobiledevicesecurity;
import java.util.List;
import android.app.Activity;
import android.content.Intent;
import android.graphics.Typeface;
import android.media.MediaPlayer;
import android.os.Build;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
public class Quiz extends Activity
{
List<Question> questionList;
int score = 0;
int qid = 0;
Question currentQuest;
TextView txtQuestion, scored;
Button button1, button2, button3;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_quiz);
QuizHelper db = new QuizHelper(this);
questionList = db.getAllQuestions();
currentQuest = questionList.get(qid);
txtQuestion = (TextView) findViewById(R.id.txtQuestion);
button1 = (Button) findViewById(R.id.button1);
button2 = (Button) findViewById(R.id.button2);
button3 = (Button) findViewById(R.id.button3);
scored = (TextView) findViewById(R.id.score);
setQuestionView();
button1.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View v) {
getAnswer(button1.getText().toString());
}
});
button2.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View v) {
getAnswer(button2.getText().toString());
}
});
button3.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View v) {
getAnswer(button3.getText().toString());
}
});
}
public void getAnswer(String AnswerString)
{
if (currentQuest.getAnswer().equals(AnswerString))
{
score++;
scored.setText("Score : " + score);
}
else
{
Intent intent = new Intent(Quiz.this,
Result.class);
Bundle b = new Bundle();
b.putInt("score", score);
intent.putExtras(b);
startActivity(intent);
finish();
}
if (qid < questionList.size()) {
currentQuest = questionList.get(qid);
setQuestionView();
}
else
{
Intent intent = new Intent(Quiz.this,
Result.class);
Bundle b = new Bundle();
b.putInt("score", score);
intent.putExtras(b);
startActivity(intent);
finish();
}
}
private void setQuestionView()
{
txtQuestion.setText(currentQuest.getQuest());
button1.setText(currentQuest.getOption1());
button2.setText(currentQuest.getOption2());
button3.setText(currentQuest.getOption3());
qid++;
}
}
Result.java
Code:
package app.mobiledevicesecurity;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
public class Result extends Activity {
private static Button playbtn;
private static Button menubutton;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_result);
OnClickPlayButtonListener();
OnClickMenuButtonListener();
TextView textResult = (TextView) findViewById(R.id.textResult);
Bundle b = getIntent().getExtras();
int score = b.getInt("score");
textResult.setText("You scored" + " " + score + " for the quiz.");
Intent intent2 = new Intent(Result.this,
Scores.class);
Bundle bun = new Bundle();
bun.putInt("score", score);
intent2.putExtras(bun);
startActivity(intent2);
finish();
}
public void OnClickPlayButtonListener() {
playbtn = (Button) findViewById(R.id.btn);
playbtn.setOnClickListener(
new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent("app.mobiledevicesecurity.Quiz");
startActivity(intent);
}
}
);
}
public void OnClickMenuButtonListener() {
menubutton = (Button) findViewById(R.id.menubtn);
menubutton.setOnClickListener(
new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(getApplicationContext(), MainActivity.class);
startActivity(intent);
}
}
);
}
}
Scores.java
Code:
package app.mobiledevicesecurity;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.TextView;
import android.content.Intent;
public class Scores extends ActionBarActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_scores);
TextView txtScore1 = (TextView) findViewById(R.id.txtScore1);
Bundle bun = getIntent().getExtras();
int score = bun.getInt("score");
txtScore1.setText("score:" + " " + score + " for the quiz.");
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_scores, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
You are doing it wrong once you send the intent to start the Result Activity you have this code on your onCreate method:
Intent intent2 = new Intent(Result.this,
Scores.class);
Bundle bun = new Bundle();
bun.putInt("score", score);
intent2.putExtras(bun);
startActivity(intent2);
finish();
Which causes the Result activity to launch Scores and close Result
Please move this code out of your onCreate method and only call it when you need to!
Can you maybe help me with this. I am in the process of learning this application development. The score must be passed over to the Scores.java activity
This is what I tried but it do not work:
Result.java:
Code:
package app.mobiledevicesecurity;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
public class Result extends Activity {
private static Button playbtn;
private static Button menubutton;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_result);
OnClickPlayButtonListener();
OnClickMenuButtonListener();
TextView textResult = (TextView) findViewById(R.id.textResult);
Bundle b = getIntent().getExtras();
int score = b.getInt("score");
textResult.setText("You scored" + " " + score + " for the quiz.");
}
public void getScore()
{
Bundle b = getIntent().getExtras();
int score = b.getInt("score");
Intent intent2 = new Intent(Result.this,
Scores.class);
Bundle bun = new Bundle();
bun.putInt("score", score);
intent2.putExtras(bun);
startActivity(intent2);
finish();
}
public void OnClickPlayButtonListener() {
playbtn = (Button) findViewById(R.id.btn);
playbtn.setOnClickListener(
new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent("app.mobiledevicesecurity.Quiz");
startActivity(intent);
}
}
);
}
public void OnClickMenuButtonListener() {
menubutton = (Button) findViewById(R.id.menubtn);
menubutton.setOnClickListener(
new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(getApplicationContext(), MainActivity.class);
startActivity(intent);
}
}
);
}
}
Scores.java:
Code:
package app.mobiledevicesecurity;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.TextView;
import android.content.Intent;
public class Scores extends ActionBarActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_scores);
Result res = new Result();
res.getScore();
TextView txtScore1 = (TextView) findViewById(R.id.txtScore1);
Bundle bun = getIntent().getExtras();
int score = bun.getInt("score");
txtScore1.setText("Last quiz score:" + " " + score + ".");
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_scores, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
Logcat:
Code:
09-08 20:47:51.143 1050-1050/app.mobiledevicesecurity E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: app.mobiledevicesecurity, PID: 1050
java.lang.RuntimeException: Unable to start activity ComponentInfo{app.mobiledevicesecurity/app.mobiledevicesecurity.Scores}: java.lang.NullPointerException: Attempt to invoke virtual method 'android.os.Bundle android.content.Intent.getExtras()' on a null object reference
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2325)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2390)
at android.app.ActivityThread.access$800(ActivityThread.java:151)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5257)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'android.os.Bundle android.content.Intent.getExtras()' on a null object reference
at app.mobiledevicesecurity.Result.getScore(Result.java:31)
at app.mobiledevicesecurity.Scores.onCreate(Scores.java:18)
at android.app.Activity.performCreate(Activity.java:5990)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2278)
************at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2390)
************at android.app.ActivityThread.access$800(ActivityThread.java:151)
************at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303)
************at android.os.Handler.dispatchMessage(Handler.java:102)
************at android.os.Looper.loop(Looper.java:135)
************at android.app.ActivityThread.main(ActivityThread.java:5257)
************at java.lang.reflect.Method.invoke(Native Method)
************at java.lang.reflect.Method.invoke(Method.java:372)
************at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
************at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
This is wrong:
Result res = new Result();
res.getScore();
You are instantiating a new Result Activity which of course will have a null bundle because its not the same original Result Activity! What you are doing is the same has storing something on your box object named "box1" and then create a new box named "box2" and hope the object you stored will be on this new box!
If i understood correctly you want to show the result activity on the end of the quiz which you seemed to have working. And now you want to show the scores activity on press of a button on the main activity correct?
For that create a listener for the scores button on your Main Activity and add code to launch the Scores Activity with an intent where you pass the score. And then retrieve the bundle on your onCreate method on your ScoresActivity!
Can you maybe help me. I understand what you say but do not know how to do it.
Here is my main activity:
Code:
package app.mobiledevicesecurity;
import android.content.Intent;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;
public class MainActivity extends ActionBarActivity {
DatabaseHelper myDb;
private static Button readbtn;
private static Button quizbtn;
private static Button scoresbtn;
private static Button settingsbtn;
private static Button helpbtn;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
myDb = new DatabaseHelper(this);
myDb.insertData();
OnClickReadButtonListener();
OnClickQuizButtonListener();
OnClickScoresButtonListener();
OnClickSettingsButtonListener();
OnClickHelpButtonListener();
}
public void OnClickReadButtonListener() {
readbtn = (Button) findViewById(R.id.readbutton);
readbtn.setOnClickListener(
new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent("app.mobiledevicesecurity.Read_Category");
startActivity(intent);
}
}
);
}
public void OnClickQuizButtonListener() {
quizbtn = (Button) findViewById(R.id.quizbutton);
quizbtn.setOnClickListener(
new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent("app.mobiledevicesecurity.Quiz");
startActivity(intent);
}
}
);
}
public void OnClickScoresButtonListener() {
scoresbtn = (Button) findViewById(R.id.scoresbutton);
scoresbtn.setOnClickListener(
new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent("app.mobiledevicesecurity.Scores");
startActivity(intent);
}
}
);
}
public void OnClickSettingsButtonListener() {
settingsbtn = (Button) findViewById(R.id.settingsbutton);
settingsbtn.setOnClickListener(
new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent("app.mobiledevicesecurity.Settings");
startActivity(intent);
}
}
);
}
public void OnClickHelpButtonListener() {
helpbtn = (Button) findViewById(R.id.helpbutton);
helpbtn.setOnClickListener(
new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent("app.mobiledevicesecurity.Help");
startActivity(intent);
}
}
);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
Android Studio Eclipse - 1
I wonder if I 10 of the many many who call to use FDI. In my 20 years I have been on 1: MS Visual Studio, 2: Eclipse 3: STS (spring version of Eclipse), 4: RAD (IBM Websphere version eclipse commercially), 5: and now Netbeans 6: IntelliJ. The last one is my favorite by far far away. When you say many many Suppose you can take a little more to the list?
I let Visual Studio, because I. To Java instead of C ++ I went into eclipse, because that's what everyone else was doing, so I thought it was the only tool. I moved to STS because I look for alternatives, because eclipse was anything but stable, if you use EJB, Spring, Hibernate and one of the usual suspects in the application server where the debugging and publishing is a very regular basis. I had to use RAD, because a customer forced me. RAD6.2 and if the company that I was, I was probably still sued IBM as RAD6.2 is not even worth called a beta version. Since none of the releabed of the Eclipse-based IDE agony I have so hard to avoid, tried, I tried NetBeans. And things clarified. By integrating Maven was better than the eclipse. Honesty I admit liable that I never really know him so well, because professional, everyone was from Eclipse moving to IntelliJ, and I felt nothing but relief, where once swore. And so I joined the hive.
And I'm glad that I did it. IntelliJ is not perfect, but in my humble opinion, approaches. And if you have a problem, send an email to get these people and nine out of ten an answer within an hour. In the worst case within a day. At least in my case, as a paying customer.
I can not comment on Eclipse with the development of Android. I am pleased to talk about Java developers. For me, the Eclipse is a past long forgotten. Never again.
#Eclipse.
The Wrong Activity Shows Up Android Studio OK - we have it, you hate Eclipse. Personally, I find that the argument pointless. I do not like Eclipse, but I have many, many IDEs that were much worse used. Many developers - including myself - to live well with Eclipse for the daily work, either by choice or simply because we have to. Is set correctly Eclipse IDE a solid. Arguing that it fragile, even if the "stable" version of Android Studio still hangs / freezes it seems quite often rather disingenuous.
The other thing, this article makes completely useless is that they are all reasons (mostly true) for the reason why Android Studio is listed size. They forget to mention the various reasons - equally valid - because Android Studio is terrible (in the same way that we speak only bad problems with Eclipse, but none of its strengths).
Personally, I think Android Studio is practically dead, and is never more than a footnote in the history of the development of Android to be. One reason is due to the fact the unit - another is simply the inevitable course of development.
# 1 Android libraries
More than a year has passed since the AS was launched, and Google has not yet developed a sensible approach with Android libraries. Never tried above also brings a relatively simple configuration library? I tried to explain how to install the libraries in Android as for a new developer? There are zero relevant documents on the website and 50% of what it is out of date on the Internet - the remaining 50% is a terrible reading. Re usability of the code is the cornerstone of good development practices, but there are exercises that suggest in all seriousness physically copy code between projects in Android Studio. 1970 called ...
Inability of Google to provide a simple and intuitive code reuse mechanical - especially after (finally) it did work in Eclipse, IMO is the only major flaw Android Studio. At the same time makes it impossible for developers to have a choice (for example, everything is in Eclipse or AS) is just icing on the cake.
Even if - if you can just explain how multiple applications with multiple libraries Androdi (and some libraries use each other) set up, then I would see such a blog post. More than that - I would be very impressed. I tried it myself and it failed - and I have not seen anyone doing it. IMO - when a build tool is only for experts, it is a poor tool of creation. Gradle for Android is just that. Few can the software companies, technology that afford to introduce to understand only 1-2 people at home.
# 2 Google is not interested in having Android SDK to survive
For me, this is the largest study problem Android. It is an IDE for what developed a dying language. Android Studio is already dead.
Why? Since cross-platform (ie, at least Android + IOS) is the only sensible choice if you want to start the development of mobile applications today. Limit yourself to a single platform is just silly - and especially for the Games (which is - I would remind you - 90% of sales in the App Store), there are many, many excellent multi-platform tools like unit and Cocos2dx. None of them have Java or the Android SDK as a development language.
If Google wanted Android Java must be more than a footnote in history, they would have made an effort - any effort - it is Java Android cross-compiled on other platforms. At least one could the Android SDK can create programs Chrome, or even Android applications compiled directly from desktop applications. Both would be relatively simple. They will not, though. Instead dithering about Android and Chrome OS they want to support.
Of course - some argue that Google has already decided, and the choice is Chrome OS. Soon you can applications can run Chrome either in Chrome OS, Android, iOS and Google (has already announced that, based on Apache Cordoba) Personally, I'm not quite sure that Google has not to develop their minds yet, but ultimately developing the Community to make the choice for them, and is not to be Android SDK.
I'm not saying that he die this year or next - but at some point it becomes very clear that Google is not interested in who became the development of native Android (in typical Google approach, it does not surprise me if it even makes it Studio to Android 1.0). And I say this not because I hate Android - I love the strengths of the Android SDK, and I would no more joy love to hear Google ads to make I / O to show that they are going to the Android SDK build. I doubt that will happen when.
Ironically, starting as a developer, leaving Android SDK (Android and Studio), one of the languages ​​that are likely to encounter, JavaScript (the language of choice for Google Chrome OS), which often lead people back in .... Eclipse.

Trouble with implementing In App Billing into my app...

So I was programming in some In app Billing code for my Android app using Android Studio. I was following an Android tutorial called 'Preparing your In-app Billing Application' at the Android Developer website (not allowed to give a link because I'm a new user). All was going well, until I get to the part where I have to paste their code into my code. Check out their code put into mine (I left the base64EncodedPublicKey empty so nobody would steal it):
Code:
public class MainActivity extends ActionBarActivity {
//Add other java files to the main class
private JokeBook mJokeBook = new JokeBook();
private ColorWheel mColorWheel = new ColorWheel();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//Declare View variables
final TextView jokeLabel = (TextView) findViewById(R.id.jokeTextView);
final Button showJokeButton = (Button) findViewById(R.id.showJokeButton);
final RelativeLayout relativeLayout = (RelativeLayout) findViewById(R.id.relativeLayout);
final Button moreJokes = (Button) findViewById(R.id.moreJokes);
//On Click
View.OnClickListener listener = new View.OnClickListener() {
@Override
public void onClick(View v) {
String joke = mJokeBook.getJoke();
//Update label with fact
jokeLabel.setText(joke);
int color = mColorWheel.getColor();
relativeLayout.setBackgroundColor(color);
showJokeButton.setTextColor(color);
moreJokes.setTextColor(color);
}
};
showJokeButton.setOnClickListener(listener);
goToTwitter();
goToFacebook();
goToExxellerate();
IabHelper mHelper;
@Override
public void [U]onCreate(Bundle savedInstanceState)[/U] {
// ...
String base64EncodedPublicKey = "";
// compute your public key and store it in base64EncodedPublicKey
[B]mHelper = new IabHelper(this, base64EncodedPublicKey);[/B]
}
mHelper.startSetup(new IabHelper.OnIabSetupFinishedListener() {
public void onIabSetupFinished(IabResult result) {
if (!result.isSuccess()) {
// Oh noes, there was a problem.
[I]Log.d(TAG, "Problem setting up In-app Billing: " + result);[/I]
}
// Hooray, IAB is fully set up!
}
});
@Override
public void [U]onDestroy()[/U] {
super.onDestroy();
if (mHelper != null) mHelper.dispose();
mHelper = null;
}
}
The code that they gave me had many errors when pasted into Android Studio, which were:
TAG has private access in 'android.support.v4.app.FragmentActivity' (Italicized text)
Annotations are not allowed here (@Override)
; expected (Underlined text)
IabHelper (android.view.View.onClickListener, String) in IabHelper cannot be applied to (com.exxellerate.joketeller.MainActivity, String) (Bolded Text)
Any help with fixing there errors? I'm a beginner at code and very confused that the code they gave me was wrong...

OnClickListener in a Fragment

Hi,
I'm new to Android development and I'm developing my first Android app about music that contains two fragments: Home Fragment and Genres Fragment. This app is a school project and it's kinda urgent.
In Genres Fragment, I have four ImageButtons and I want to add some action to them, like when clicking a button, it goes to another fragment
So, in the Java file of that fragment, I already have the code for OnClickListener but I don't know what to put in the case condition of each button.
P.S: I can't post images because is says: "All new users prevented from posting outside links in their message". So, instead of an image, I will post the code.
Code:
public class GenresFragment extends Fragment implements View.OnClickListener{
public GenresFragment() {
// Required empty public constructor
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View v = inflater.inflate(R.layout.fragment_genres, container, false);
ImageButton rapBtn = (ImageButton)v.findViewById(R.id.RapButton);
ImageButton popBtn = (ImageButton)v.findViewById(R.id.PopButton);
ImageButton edmBtn = (ImageButton)v.findViewById(R.id.EDMButton);
ImageButton rockBtn = (ImageButton)v.findViewById(R.id.RockButton);
rapBtn.setOnClickListener(this);
popBtn.setOnClickListener(this);
edmBtn.setOnClickListener(this);
rockBtn.setOnClickListener(this);
return v;
}
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.RapButton:
break;
case R.id.PopButton:
break;
case R.id.EDMButton:
break;
case R.id.RockButton:
break;
}
}
}
Can you help me with this?
Thank you
Replace the fragment on button click
Hello,
you just need to replace the fragment on button click.
// Create new fragment and transaction
Fragment newFragment = new ExampleFragment();
FragmentTransaction transaction = getFragmentManager().beginTransaction();
// Replace whatever is in the fragment_container view with this fragment,
// and add the transaction to the back stack if needed
transaction.replace(R.id.fragment_container, newFragment);
transaction.addToBackStack(null);
// Commit the transaction
transaction.commit();
Thanks!

Using Intent(send mail) in Navigation drawer

I want to send mail from Navigation Drawer using the intent. First, my MainActivity.
Code:
else if(id==R.id.nav_mail) {
fragment = new MailFragment();
}
and MailFragment.
Code:
public class MailFragment extends Fragment {
public MailFragment() {
Intent email = new Intent(Intent.ACTION_SEND);
email.setType("plain/text");
String[] address = {"********@gmail.com"};
email.putExtra(Intent.EXTRA_EMAIL, address);
email.putExtra(Intent.EXTRA_SUBJECT, "Subject___****");
email.putExtra(Intent.EXTRA_TEXT, "Text___****.\n\n");
startActivity(email);
}
// @Override
// public View onCreateView(LayoutInflater inflater, ViewGroup container,
// Bundle savedInstanceState) {
// TextView textView = new TextView(getActivity());
// textView.setText(R.string.hello_blank_fragment);
// return textView;
// }
}
Run to create crash. The reason why I used to use fragment is because I made the simple screen change function fragment.
If you need more code, comment plz.
I didn't get what you are trying to do. If you are trying to invoke the "Select your mail app" screen and then send a message thru the Intent all of this when the user clicks on a row on the drawer then you should just copy the code to
Code:
else if(id==R.id.nav_mail) {
// here
}
without switching any fragment.
By the way, as far as I know, the fragment's public constructor must be empty.
You cannot do it from Fragment's constructor. Move your code to onActivityCreated() method.
qlife1146 said:
I want to send mail from Navigation Drawer using the intent. First, my MainActivity.
Code:
else if(id==R.id.nav_mail) {
fragment = new MailFragment();
}
and MailFragment.
Code:
public class MailFragment extends Fragment {
public MailFragment() {
Intent email = new Intent(Intent.ACTION_SEND);
email.setType("plain/text");
String[] address = {"********@gmail.com"};
email.putExtra(Intent.EXTRA_EMAIL, address);
email.putExtra(Intent.EXTRA_SUBJECT, "Subject___****");
email.putExtra(Intent.EXTRA_TEXT, "Text___****.\n\n");
startActivity(email);
}
// @Override
// public View onCreateView(LayoutInflater inflater, ViewGroup container,
// Bundle savedInstanceState) {
// TextView textView = new TextView(getActivity());
// textView.setText(R.string.hello_blank_fragment);
// return textView;
// }
}
Run to create crash. The reason why I used to use fragment is because I made the simple screen change function fragment.
If you need more code, comment plz.
Click to expand...
Click to collapse
Creating a new Intent in the constructor is a really bad idea. An example from the android's developer guide
Code:
public class MainActivity extends AppCompatActivity {
public static final String EXTRA_MESSAGE = "com.example.myfirstapp.MESSAGE";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
/** Called when the user taps the Send button */
public void sendMessage(View view) {
Intent intent = new Intent(this, DisplayMessageActivity.class);
EditText editText = (EditText) findViewById(R.id.editText);
String message = editText.getText().toString();
intent.putExtra(EXTRA_MESSAGE, message);
startActivity(intent);
}
}

Categories

Resources