Android Studio - JavaDoc comments not generating - android

I have one problem with the comments in Android Studio.
My template file (File Header) Is like this:
/**
* Created by ${USER} on ${DATE}.
*/
When I create new class, or Interface my comment header gets automatically generated, and this works.
But when I generate: activity, fragment, application, services, the comment does not generate. I really do not know where is the problem.
Here is the Activity template description. But when I create new Activity, the comment does not appear, and every time I need to retype it.
package ${PACKAGE_NAME};
import android.app.Activity;
import android.os.Bundle;
#parse("File Header.java")
public class ${NAME} extends Activity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
}
Thanks!

To generate comments type /** above the method name and press enter. You can also use a tool under Android Studio menu:
Tools > Generate JavaDoc

Related

Where do I place OnItemClickListener?

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?

Can't be resolved as a type android Eclipse

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).

findviewbyid not working

Eclipse is not recognizing R.id. I just started learning Android so please help me out here.
import android.app.Activity;
import android.os.Bundle;
import android.widget.EditText;
public class SecondappActivity extends Activity {
EditText ed;
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
ed=(EditText) findViewById(R.id.b1);
}
}
it is saying id cannot be resolved or is not a field
Check your xml file and make sure it doesn't have any error. Looks like there is a problem with generating R file. It can be caused by errors in xml.
Check for any errors in your xml files or your res folder. Clean and rebuild project. It will work
What does your main.xml file look like?
There is nothing wrong with your java code. Assuming all your imports are working.
Chances are bn1 is either not in that layout. Or you are not adding the '+' in you android:id field to make sure this goes into the R.java file.
Put
import YourWholePackage.R;
in import segment.
I have the same issue :/ I am just getting into android development and already stuck. This is my code:
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
EditText nameEditText = (EditText) findViewById(R.id.nameEditText)
}
}
Nothing fancy, just one edittext field and one button, no errors in activity_main.xml. But when I am typing findViewById - its not even available in autosuggestion list.
Thanks

Android cannot be resolved to a type

I'm getting "cannot be resolved to a type" in my code. I'm looking for solution but all solutions are not working.
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
public class Vortex extends Activity {
private static final String LOG_TAG = Vortex.class.getSimpleName();
private VortexView _vortexView; //there is the problem
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
_vortexView = new VortexView(this);
setContentView(_vortexView);
}
}
The problem is with VortexView in this code. Eclipse tell me that VortexView cannot be resolved to a type.
Any solution?
Do you have VortexView class in your project, if so, ctrl+shift+O will resolve the issue. Otherwise add class/jar to classpaht and do ctrl+shift+O (organize imports).
VortexView is your custom view? If there exists VortexView.class
Probably, you have made either of the following two mistakes.
You have not extended a view named VortexView at all
You have extended it correctly, but you haven't made it available to the current package
When you are doing such things, it is better to define custom views inside the same package. Or even though you are defining it somewhere else, make it avilable where it is used.
import yourPackage.VortexView;
Hope this helps.

r.id not regenerated

I am trying to create a simple button example, but when I add this code:
mButton = (Button) findViewById(R.id.button1);
it wont update my R.id file. I've tried everything including making sure automatic build is on, cleaning the project, and updating the SDK. This happens in both 1.6 and 2.2 projects.
Here's what full code is looking like:
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
public class NewTest extends Activity {
Button myButton;
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
myButton = (Button) findViewById(R.id.button1);
}
}
findViewById is looking at the R.id file for the location you refer to.
Your code will not cause the file to update as it is only looking for the button.
Creating the button in your layout will cause the R.id file to update.
<Button
android:id="#+id/button1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Button One"/>
As you are using findViewById in context, and the view for the current context is main.xml, the above button example will need to be inside the main.xml file. Otherwise if you had another button with the same name in another .xml layout, the entry would be made in your R.id file but your code would give you a null pointer exception, because the button doesn't exist in the context you are trying to reference it from.
Make sure you have proper import for your app's R class in your Activity:
import your.app.package.R;
UPDATE: this implicit import is only needed if your Activity class is not in the root of your.app.package package.
Save your project before using R.id.something
Since you are using XML based Layout make sure that you have android:id attribute in the main.xml file with "#+id/button1" as its value.......
It wouldn't update the generated R.java file when you just refer to an existing id.
It only updates when you add a resource. button01 must already exist in one of your .xml files, otherwise your 'findViewById(R.id.button1)' wouldn't compile.
I had the same problem using API 19 with the layout editor set to API 15 while trying to follow the NotePadV1 tutorial. I couldn't get the R.id.text1 to compile from the notes_row.xml file.
Originally, I had just pasted text into the xml file to generate the layout. After unsuccessfully trying deleting R and a Clean, I tried deleting the notes_row layout entirely. When I recreated the layout, I used the graphical interface to add the properties of the TextView object, just the Id #+id/text1, width and height. Then I did a Clean and compile. It worked.

Categories

Resources