English 中文(简体)
“对制造的类型没有定义”
原标题:"The method setListAdapter(ArrayAdapter) is undefined for the type create"

我完全是新鲜的, j和roid,因此,我试图从海底和数据库中找到有用的样本。 我发现这个项目的博客:

rel=“nofollow noreferer”>http://saigeethamn.blogspot.com/2009/10/android-developer-tutorial-12.html

我主持了该项目,并做了一些细微的工作,但我正试图建立一个复制和复制的新项目;沿用了其中的守则,这并不奏效。

我在此问题上有问题:

this.setListAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1,results));

这是我发现的错误:

用于制造类型的方法没有界定

它像C#中的一种方法,但我可以在原项目中找到这种方法。

我在哪里犯错误?

最佳回答

当您打电话this.setListAdapter时,这必须延伸ListActective,大概仅限您上下班Actative

问题回答

这项法典对我来说是可行的。

package com.Itrack.Mobile;

import java.util.ArrayList;
import android.app.ListActivity;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.SimpleCursorAdapter;
import android.widget.TextView;
import android.widget.Toast;

public class listV extends ListActivity {
public SQLiteDatabase db;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

       // Check if the database exist  //
    db = openOrCreateDatabase(
            "itrackmobile.sqlite"
            , SQLiteDatabase.CREATE_IF_NECESSARY
            , null
            );

    try
    {
        Cursor c = db.query("basico", new String[]      
         {"_id","codigo","cantidad","fecha"},null,null,null,null,null);

        // rutina de prueba //
                ArrayList<String> mArrayList = new ArrayList<String>();
                c.moveToFirst();
                while(!c.isAfterLast()) {
                     mArrayList.add("ID: " +c.getString(c.getColumnIndex("_id")) + 
           "
Codigo : " + c.getString(c.getColumnIndex("codigo")) + "
Cantidad : " 
           + c.getString(c.getColumnIndex("cantidad")) + "
Fecha : " +     
           c.getString(c.getColumnIndex("fecha")) );
                      c.moveToNext();
             }

                setListAdapter( new ArrayAdapter<String>  
               (this,R.layout.single_item,mArrayList));
                ListView  list  = getListView();
                list.setTextFilterEnabled(true);
                list.setOnItemClickListener(new OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> arg0, View arg1,
                            int arg2, long arg3) {

                     Toast.makeText(getApplicationContext(), ((TextView) 
                      arg1).getText(), Toast.LENGTH_SHORT).show();
                    }

                });
    }
    catch (RuntimeException e)
    {
        Log.e("basico", e.toString(), e);
    }



}


}




相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...