So I'm pretty new to android development and have been trying to piece together some code bits. Here's what I have so far:
package com.teslaprime.prirt;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ListView;
import an开发者_如何转开发droid.widget.AdapterView.OnItemClickListener;
import java.util.ArrayList;
import java.util.List;
public class TaskList extends Activity {
List<Task> model = new ArrayList<Task>();
ArrayAdapter<Task> adapter = null;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button add = (Button) findViewById(R.id.add);
add.setOnClickListener(onAdd);
ListView list = (ListView) findViewById(R.id.tasks);
adapter = new ArrayAdapter<Task>(this,android.R.layout.simple_list_item_1,model);
list.setAdapter(adapter);
list.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(View v, int position, long id) {
adapter.remove(position);
}
});}
private View.OnClickListener onAdd = new View.OnClickListener() {
public void onClick(View v) {
Task task = new Task();
EditText name = (EditText) findViewById(R.id.taskEntry);
task.name = name.getText().toString();
adapter.add(task);
}
};
}
and here are the errors I'm getting:
compile:
[javac] /opt/android-sdk/tools/ant/main_rules.xml:384: warning: 'includeantruntime' was not set, defaulting to build.sysclasspath=last; set to false for repeatable builds
[javac] Compiling 2 source files to /home/chris-kun/code/priRT/bin/classes
[javac] /home/chris-kun/code/priRT/src/com/teslaprime/prirt/TaskList.java:30: <anonymous com.teslaprime.prirt.TaskList$1> is not abstract and does not override abstract method onItemClick(android.widget.AdapterView<?>,android.view.View,int,long) in android.widget.AdapterView.OnItemClickListener
[javac] list.setOnItemClickListener(new OnItemClickListener() {
[javac] ^
[javac] /home/chris-kun/code/priRT/src/com/teslaprime/prirt/TaskList.java:32: remove(com.teslaprime.prirt.Task) in android.widget.ArrayAdapter<com.teslaprime.prirt.Task> cannot be applied to (int)
[javac] adapter.remove(position);
[javac] ^
[javac] 2 errors
BUILD FAILED
/opt/android-sdk/tools/ant/main_rules.xml:384: Compile failed; see the compiler error output for details.
Total time: 2 seconds
any ideas?
I'm not an Android programmer, but it's referring to this line:
list.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(View v, int position, long id) {
adapter.remove(position);
}
});}
You have the method signature of View, int, long, and it wants
AdapterView<?> parent, View view, int position, long id as the signature
As for the second issue, it's saying
The remove method for adapter requires a
Task
object not an integer.
An abstract
class contains unimplemented methods. If you want to extend it, you must implement the unimplemented methods. Eclipse will tell you when you don't do what you have to and, if you click on the red "x", will give you the suggested solutions to these problems. In this case, it will automatically include the method signatures for these abstract methods you have not implemented.
精彩评论