So the story is that basically, I'm making a very simple app so that my place of employment can send the closing logs every night with ease. I have all of the text boxes to enter the information, and then at the bottom there is a checkbox and submit like so..
There is a template for the email that we edit manually every night, and basically I want to take all of the information received in the text boxes (all have their own ID, etc.) and plug it into the email template that I currently have - and send it to the emails of the employees (6 people).
Can someone lead me in the right direction, or show me how I would go about this problem?
MainActivity.java
package savo.nicholas.bestb;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
I've constructed a bunch of these to get the values from the form. I'm looking to plug these values into a pre-formatted email and send them.
public EditText getGm() //$ of GM
{
return (EditText)findViewById(R.id.gm);
}
Thanks!
Nick
I have built a test app that shows few records on a listview.
Now I want to click on an item and see the info on the debug of android studio.
I know I'm supposed to create an OnItemClickListener but I'm not sure where I'm supposed to place it.
I tried placing it on the mainactivity, the app works, but the click function is never called, so there is something wrong.
I looked around Google for some help, but I couldn't wrap my mind around it.
It should be a straightforward action (I have a list, I click an item) but I am not able to make it work.
This what I tried so far:
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;
import java.util.LinkedList;
import java.util.List;
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ListView listView = (ListView) findViewById(R.id.listViewDemo);
List list = new LinkedList();
list.add(new Contatto("Antonio","Rossi","1234567890"));
list.add(new Contatto("Pino","Bianchi","2345678901"));
list.add(new Contatto("Peppe","Verdi","3456789012"));
list.add(new Contatto("Leo","Rossi","4567890123"));
list.add(new Contatto("Mario","Blu","5678901234"));
list.add(new Contatto("Aldo","Da Vinci","6789012345"));
CustomAdapter adapter = new CustomAdapter(this, R.layout.rowcustom,list);
listView.setAdapter(adapter);
OnItemClickListener clickListener = new OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> adapter, View view,
int position, long id) {
Contatto c = (Contatto)adapter.getItem(position);
Log.d(c.getNome(),c.getTelefono());
}
};
listView.setOnItemClickListener(clickListener);
}
}
OnItemClickListener is not recognized, and getItem neither.
The autocorrect of android Studio proposes me to change to "AdapterView.OnItemClickListener", getItem has nooptions to be recognized.
I tried to add " implements OnItemClickListener" on the class declaration, but it doesn't work either (gives error, name is in red, no solutions are provided by the android studio).
At one point I was able to remove all errors, but the code still didn't work and I don't remember what I did, I was just fiddling.
You can put the OnClickListener in onCreate()
If you post your code, that would certainly help
There are a couple of things that are questionable about the code you posted.
You create OnItemClickListener but you don't have an import for AdapterView.OnItemClickListener. So are you sure you're using the right class?
Inside your onItemClick, you reference adapter, which is the local parameter of type AdapterView<?>, but AdapterView has no such method getItem(int). It can't be a reference to your CustomAdapter because that's not declared final.
Your use of Log.d(c.getNome(),c.getTelefono()); is wrong. The various log methods take a "tag" as the first parameter. It could be that you're not seeing the log messages because that's just wrong.
So, really, this shouldn't even compile. Please review your code and post the most recent, most correct, most compilable version you have. Including the code for you custom adapter and layout wouldn't hurt either.
Have you tried using your debugger to step through this code and seeing if a breakpoint at the click point gets hit?
It is saying that popupWindow.OnDismissListner Can't be resolved as a type and when I hover the mouse over it the only option I get is to make it an interface, which isn't what I want to do.
public class MainActivity extends Activity implements OnItemSelectedListener,
PopupWindow.OnDismissListener, View.OnClickListener {
I am unsure exactly what is wrong. I imported android.widget.PopupWindow.OnDismissListener; and it still is giving the error. I am trying to get a menu to pop up with a list of dice and when a dice is clicked it will return a matching int value based on how many sides the dice has. I have no other errors except the one mentioned above.
Try replacing
import android.widget.PopupWindow.OnDismissListener;
with
import android.widget.PopupWindow;
Or simply use OnDismissListener in your code (not PopupWindow.OnDismissListener).
I'm trying to get the text from one XML to another but it just crashes when its supposed to happen so any help will be welcomed!
Here is the code by the way
package com.android.test1;
import android.app.Activity;
import android.os.Bundle;
import android.widget.EditText;
import android.widget.TextView;
public class xmltwo extends Activity{
#Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.xmltwo);
TextView one = (TextView) findViewById(R.id.textView1);
EditText two = (EditText) findViewById(R.id.editText1);
one.setText(two.getText());
}
}
That's from the java file that opens the XML where the textView is.
My guess?
The logcat will be showing a NullPointerException for the line one.setText(two.getText()); because the layout file referenced by R.layout.xmltwo doesn't actually contain a TextView with an id of R.id.textView1 so the TextView called one is null.
Either that or that layout file doesn't contain an EditText with an id of R.id.editText1 which will make that null and cause an NPE when trying to call two.getText().
Just as an extra bit of information, if you want to get the text from an EditText you need to use getText().toString()
In this article Android: edit textview defined in xml one of the members has a similar issue. They theorize that possibly setContentView hasn't finished running yet and that may be the issue. However, you're saying that it is just completely crashing so I'm not sure if that could be the problem.
Could there be another part of your in your super class that could be hanging up? Could you use the getString() function instead perhaps?
I hope some of this might be helpful! I am interested in finding a solution so I intend to keep on reading to try and help!
try
one.setText(two.getText().toString().trim()+"");
hope this help..
I'm new to develop Android Apps and writing java. But, I only want to make a simple app that will give a different output on TextView depending on what time of the day it is.
F.ex. If the time is between 06:45 and 08:45 I want it to say "Good Morning", and so forth.
I have been playing with Eclipse and created a simple WebView-app but I can't seem to find any information to either choose which TextView I want shown on a specific time or show a different layout.
Do you have any tips?
This is my .java file in src for now.
package com.wao.texttime;
import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;
public class TextTime extends Activity {
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
TextView tv1 = (TextView) findViewById(R.id.TextView01);
tv1.setText("Good Morning");
}
}
There is no need to switch between different TextViews. If you just want to display different messages in your TextView I would simply call the setText function to update the TextView's text attribute.