Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/github/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android AutoCompleteTextView-类型字符串的方法setText(String)未定义_Android_Autocompletetextview_Settext - Fatal编程技术网

Android AutoCompleteTextView-类型字符串的方法setText(String)未定义

Android AutoCompleteTextView-类型字符串的方法setText(String)未定义,android,autocompletetextview,settext,Android,Autocompletetextview,Settext,我正在处理AutoCompleteTextView,我的AutoCompleteTextView的最终结果应该是这样的(从和到) 但是我在setText上有一个错误。它给我看了这个 类型字符串的方法setText(String)未定义 我不知道它出了什么问题。错误在FindMePlace.java,请帮助我 AutoCompleteDBAdapter.java import java.io.FileOutputStream; import java.io.IOException; import

我正在处理AutoCompleteTextView,我的AutoCompleteTextView的最终结果应该是这样的(从和到) 但是我在
setText
上有一个错误。它给我看了这个

类型字符串的方法setText(String)未定义

我不知道它出了什么问题。错误在FindMePlace.java,请帮助我

AutoCompleteDBAdapter.java

import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import android.app.Activity;
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.SQLException;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteException;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;

public class AutoCompleteDbAdapter {

    private static final int DATABASE_VERSION = 1;
    private static final String DB_PATH = "data/data/com.example.ukmlocationsearching/databases/";
    private static final String DATABASE_NAME = "AcademicLocation";
    private static final String TABLE_NAME = "UKMRoute";

    private static final String KEY_ROUTEID = "ID_route";
    private static final String KEY_FROMLOCATION = "FromLocation";
    private static final String KEY_TODESTINATION = "ToDestination";
    private static final String KEY_ROUTE1 = "Route1";
    private static final String KEY_ROUTE2 = "Route2";

    private DatabaseHelper mDbHelper;
    private SQLiteDatabase mDb;
    private final Activity mActivity;

    // private final Context myContext;

    private class DatabaseHelper extends SQLiteOpenHelper {

        DatabaseHelper(Context context) {
            super(context, DATABASE_NAME, null, DATABASE_VERSION);
        }

        public void createDataBase() throws IOException {
            boolean dbExist = checkDataBase();

            if (dbExist) {
                // do nothing - database already exist
            } else {
                // By calling this method and empty database will be created
                // into the default system path
                // of your application so we are gonna be able to overwrite that
                // database with our database.
                this.getReadableDatabase();

                try {
                    copyDataBase();

                } catch (IOException e) {
                    throw new Error("Error copying database");

                }
            }
        }

        private boolean checkDataBase() {
            SQLiteDatabase checkDB = null;

            try {
                String myPath = DB_PATH + DATABASE_NAME;
                checkDB = SQLiteDatabase.openDatabase(myPath, null,
                        SQLiteDatabase.OPEN_READONLY);

            } catch (SQLiteException e) {
                // database does't exist yet.
            }

            if (checkDB != null) {
                checkDB.close();
            }
            return checkDB != null ? true : false;
        }

        private void copyDataBase() throws IOException {

            // Open your local db as the input stream
            InputStream myInput = mActivity.getAssets().open(DATABASE_NAME);

            // Path to the just created empty db
            String outFileName = DB_PATH + DATABASE_NAME;

            // Open the empty db as the output stream
            OutputStream myOutput = new FileOutputStream(outFileName);

            // transfer bytes from the inputfile to the outputfile
            byte[] buffer = new byte[1024];
            int length;
            while ((length = myInput.read(buffer)) > 0) {
                myOutput.write(buffer, 0, length);
            }

            // Close the streams
            myOutput.flush();
            myOutput.close();
            myInput.close();

        }

        public void openDataBase() throws SQLException {
            // Open the database
            String myPath = DB_PATH + DATABASE_NAME;
            mDb = SQLiteDatabase.openDatabase(myPath, null,
                    SQLiteDatabase.OPEN_READONLY);

        }

        @Override
        public synchronized void close() {

            if (mDb != null)
                mDb.close();

            super.close();

        }

        // Creating Tables
        @Override
        public void onCreate(SQLiteDatabase db) {

        }

        // Upgrading database
        @Override
        public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {

        }

    }

    public AutoCompleteDbAdapter(Activity activity) {
        this.mActivity = activity;

    }

    public AutoCompleteDbAdapter open() throws SQLException {
        mDbHelper = this.new DatabaseHelper(mActivity);
        mDb = mDbHelper.getWritableDatabase();
        return this;
    }

    /**
     * Closes the database.
     */
    public void close() {
        if (mDbHelper != null){
        mDbHelper.close();
        }
    }
//-------------------------------------------------------------------------------------

    /**
     * Return a Cursor that returns all states (and their state capitals) where
     * the state name begins with the given constraint string.
     * 
     * @param constraint
     *            Specifies the first letters of the states to be listed. If
     *            null, all rows are returned.
     * @return Cursor managed and positioned to the first state, if found
     * @throws SQLException
     *             if query fails
     */
    public Cursor getMatchingFromLocation(String constraint) throws SQLException {

        String queryString = "SELECT * FROM " + TABLE_NAME;

        if (constraint != null) {
            // Query for any rows where the state name begins with the
            // string specified in constraint.
            //
            // NOTE:
            // If wildcards are to be used in a rawQuery, they must appear
            // in the query parameters, and not in the query string proper.
            // See http://code.google.com/p/android/issues/detail?id=3153
            constraint = constraint.trim() + "%";
            queryString += " WHERE FromLocation LIKE ?";
        }
        String params[] = { constraint };

        if (constraint == null) {
            // If no parameters are used in the query,
            // the params arg must be null.
            params = null;
        }
        try {
            Cursor cursor = mDb.rawQuery(queryString, params);
            if (cursor != null) {
                this.mActivity.startManagingCursor(cursor);
                cursor.moveToFirst();
                return cursor;
            }
        } catch (SQLException e) {
            Log.e("AutoCompleteDbAdapter", e.toString());
            throw e;
        }

        return null;
    }

    /**
     * Populates the database with data on states and state capitals.
     * 
     * @param db
     *            The database to be populated; must have the appropriate table
     *            ("state") and columns ("state" and "values") already set up.
     */
    // Adding new Poi
    public void addUkmRoute(UkmRoute Ukmroute) {
        //SQLiteDatabase db = this.getWritableDatabase();

        ContentValues values = new ContentValues();
        values.put(KEY_ROUTEID, Ukmroute.getID()); // ID
        values.put(KEY_FROMLOCATION, Ukmroute.getFromLocation()); //    from
        values.put(KEY_TODESTINATION, Ukmroute.getToDestination()); // to
        values.put(KEY_ROUTE1, Ukmroute.getRoute1()); // route1
        values.put(KEY_ROUTE2, Ukmroute.getRoute2()); //  route2

        // Inserting Row
        mDb.insert(DATABASE_NAME, null, values);
        mDb.close(); // Closing database connection
    }

}
package com.example.series1;

import android.os.Bundle;
import android.app.Activity;
import android.content.Context;
import android.database.Cursor;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView;
import android.widget.Button;
import android.widget.CursorAdapter;
import android.widget.TextView;

public class FindMePlace extends Activity {

    private AutoCompleteDbAdapter mDbHelper;
    private AutoCompleteTextView fromLocation, toDestination;
    Button search;

    class ItemAutoTextAdapter extends CursorAdapter implements
            android.widget.AdapterView.OnItemClickListener {

        private AutoCompleteDbAdapter mDbHelper;

        public ItemAutoTextAdapter(AutoCompleteDbAdapter dbHelper) {
            // Call the CursorAdapter constructor with a null Cursor.
            super(FindMePlace.this, null);
            mDbHelper = dbHelper;
        }
//------------------------------------------------------------------------------------
        @Override
        public Cursor runQueryOnBackgroundThread(CharSequence constraint) {
            if (getFilterQueryProvider() != null) {
                return getFilterQueryProvider().runQuery(constraint);
            }

            Cursor cursor = mDbHelper
                    .getMatchingFromLocation((constraint != null ? constraint
                            .toString() : null));

            return cursor;
        }

        @Override
        public String convertToString(Cursor cursor) {
            //ubah name table name
            final int columnIndex = cursor.getColumnIndexOrThrow("FromLocation");
            final String str = cursor.getString(columnIndex);
            return str;
        }

        @Override
        public void bindView(View view, Context context, Cursor cursor) {
            /*final String text = convertToString(cursor);
            ((TextView) view).setText(text);*/
            final int fromColumnIndex = cursor.getColumnIndexOrThrow("FromLocation");
            final int toColumnIndex = cursor.getColumnIndexOrThrow("ToDestination");
            TextView text1 = (TextView) view.findViewById(R.id.text1);
            text1.setText(cursor.getString(fromColumnIndex));
            TextView text2 = (TextView) view.findViewById(R.id.text1);
            text2.setText(cursor.getString(toColumnIndex));
        }

        @Override
        public View newView(Context context, Cursor cursor, ViewGroup parent) {
            final LayoutInflater inflater = LayoutInflater.from(context);
            //final View view = inflater.inflate(android.R.layout.simple_dropdown_item_1line, parent, false);
            final View view = inflater.inflate(R.layout.list_item, parent, false);
            return view;
        }
//-------------------------------------------------------------------------------------------
        @Override
        public void onItemClick(AdapterView<?> listView, View view,
                int position, long id) {
            // Get the cursor, positioned to the corresponding row in the result
            // set
            Cursor cursor = (Cursor) listView.getItemAtPosition(position);

            // Get the state's capital from this row in the database.
             //**kene ubah*************capital nama database
            String fromLocation = cursor.getString(cursor.getColumnIndexOrThrow("FromLocation"));
            String toDestination = cursor.getString(cursor.getColumnIndexOrThrow("ToDestination"));

            // Update the parent class's TextView
            //mStateCapitalView.setText(fromLocation);
            fromLocation.setText("");
        }
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.find_me_place);
        AutoCompleteDbAdapter dbHelper = new AutoCompleteDbAdapter(this);
        dbHelper.open();

        fromLocation = (AutoCompleteTextView) findViewById(R.id.locationTxt);
        toDestination = (AutoCompleteTextView) findViewById(R.id.destinationTxt);
        search = (Button) findViewById(R.id.button1);

         ItemAutoTextAdapter adapter = this.new ItemAutoTextAdapter(dbHelper);
         fromLocation.setAdapter(adapter);
         fromLocation.setOnItemClickListener(adapter);
         toDestination.setAdapter(adapter);
         toDestination.setOnItemClickListener(adapter);

         /*AutoCompleteTextView fromLocation = (AutoCompleteTextView) findViewById(R.id.locationTxt);
         ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(this, R.layout.country_list, COUNTRIES);
         fromLocation.setAdapter(arrayAdapter); */

         search.setOnClickListener(new View.OnClickListener() {
            public void onClick(View view) {
                setResult(RESULT_OK);
                finish();
            }
        });
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.find_me_place, menu);
        return true;
    }

}
FindMePlace.java

import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import android.app.Activity;
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.SQLException;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteException;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;

public class AutoCompleteDbAdapter {

    private static final int DATABASE_VERSION = 1;
    private static final String DB_PATH = "data/data/com.example.ukmlocationsearching/databases/";
    private static final String DATABASE_NAME = "AcademicLocation";
    private static final String TABLE_NAME = "UKMRoute";

    private static final String KEY_ROUTEID = "ID_route";
    private static final String KEY_FROMLOCATION = "FromLocation";
    private static final String KEY_TODESTINATION = "ToDestination";
    private static final String KEY_ROUTE1 = "Route1";
    private static final String KEY_ROUTE2 = "Route2";

    private DatabaseHelper mDbHelper;
    private SQLiteDatabase mDb;
    private final Activity mActivity;

    // private final Context myContext;

    private class DatabaseHelper extends SQLiteOpenHelper {

        DatabaseHelper(Context context) {
            super(context, DATABASE_NAME, null, DATABASE_VERSION);
        }

        public void createDataBase() throws IOException {
            boolean dbExist = checkDataBase();

            if (dbExist) {
                // do nothing - database already exist
            } else {
                // By calling this method and empty database will be created
                // into the default system path
                // of your application so we are gonna be able to overwrite that
                // database with our database.
                this.getReadableDatabase();

                try {
                    copyDataBase();

                } catch (IOException e) {
                    throw new Error("Error copying database");

                }
            }
        }

        private boolean checkDataBase() {
            SQLiteDatabase checkDB = null;

            try {
                String myPath = DB_PATH + DATABASE_NAME;
                checkDB = SQLiteDatabase.openDatabase(myPath, null,
                        SQLiteDatabase.OPEN_READONLY);

            } catch (SQLiteException e) {
                // database does't exist yet.
            }

            if (checkDB != null) {
                checkDB.close();
            }
            return checkDB != null ? true : false;
        }

        private void copyDataBase() throws IOException {

            // Open your local db as the input stream
            InputStream myInput = mActivity.getAssets().open(DATABASE_NAME);

            // Path to the just created empty db
            String outFileName = DB_PATH + DATABASE_NAME;

            // Open the empty db as the output stream
            OutputStream myOutput = new FileOutputStream(outFileName);

            // transfer bytes from the inputfile to the outputfile
            byte[] buffer = new byte[1024];
            int length;
            while ((length = myInput.read(buffer)) > 0) {
                myOutput.write(buffer, 0, length);
            }

            // Close the streams
            myOutput.flush();
            myOutput.close();
            myInput.close();

        }

        public void openDataBase() throws SQLException {
            // Open the database
            String myPath = DB_PATH + DATABASE_NAME;
            mDb = SQLiteDatabase.openDatabase(myPath, null,
                    SQLiteDatabase.OPEN_READONLY);

        }

        @Override
        public synchronized void close() {

            if (mDb != null)
                mDb.close();

            super.close();

        }

        // Creating Tables
        @Override
        public void onCreate(SQLiteDatabase db) {

        }

        // Upgrading database
        @Override
        public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {

        }

    }

    public AutoCompleteDbAdapter(Activity activity) {
        this.mActivity = activity;

    }

    public AutoCompleteDbAdapter open() throws SQLException {
        mDbHelper = this.new DatabaseHelper(mActivity);
        mDb = mDbHelper.getWritableDatabase();
        return this;
    }

    /**
     * Closes the database.
     */
    public void close() {
        if (mDbHelper != null){
        mDbHelper.close();
        }
    }
//-------------------------------------------------------------------------------------

    /**
     * Return a Cursor that returns all states (and their state capitals) where
     * the state name begins with the given constraint string.
     * 
     * @param constraint
     *            Specifies the first letters of the states to be listed. If
     *            null, all rows are returned.
     * @return Cursor managed and positioned to the first state, if found
     * @throws SQLException
     *             if query fails
     */
    public Cursor getMatchingFromLocation(String constraint) throws SQLException {

        String queryString = "SELECT * FROM " + TABLE_NAME;

        if (constraint != null) {
            // Query for any rows where the state name begins with the
            // string specified in constraint.
            //
            // NOTE:
            // If wildcards are to be used in a rawQuery, they must appear
            // in the query parameters, and not in the query string proper.
            // See http://code.google.com/p/android/issues/detail?id=3153
            constraint = constraint.trim() + "%";
            queryString += " WHERE FromLocation LIKE ?";
        }
        String params[] = { constraint };

        if (constraint == null) {
            // If no parameters are used in the query,
            // the params arg must be null.
            params = null;
        }
        try {
            Cursor cursor = mDb.rawQuery(queryString, params);
            if (cursor != null) {
                this.mActivity.startManagingCursor(cursor);
                cursor.moveToFirst();
                return cursor;
            }
        } catch (SQLException e) {
            Log.e("AutoCompleteDbAdapter", e.toString());
            throw e;
        }

        return null;
    }

    /**
     * Populates the database with data on states and state capitals.
     * 
     * @param db
     *            The database to be populated; must have the appropriate table
     *            ("state") and columns ("state" and "values") already set up.
     */
    // Adding new Poi
    public void addUkmRoute(UkmRoute Ukmroute) {
        //SQLiteDatabase db = this.getWritableDatabase();

        ContentValues values = new ContentValues();
        values.put(KEY_ROUTEID, Ukmroute.getID()); // ID
        values.put(KEY_FROMLOCATION, Ukmroute.getFromLocation()); //    from
        values.put(KEY_TODESTINATION, Ukmroute.getToDestination()); // to
        values.put(KEY_ROUTE1, Ukmroute.getRoute1()); // route1
        values.put(KEY_ROUTE2, Ukmroute.getRoute2()); //  route2

        // Inserting Row
        mDb.insert(DATABASE_NAME, null, values);
        mDb.close(); // Closing database connection
    }

}
package com.example.series1;

import android.os.Bundle;
import android.app.Activity;
import android.content.Context;
import android.database.Cursor;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView;
import android.widget.Button;
import android.widget.CursorAdapter;
import android.widget.TextView;

public class FindMePlace extends Activity {

    private AutoCompleteDbAdapter mDbHelper;
    private AutoCompleteTextView fromLocation, toDestination;
    Button search;

    class ItemAutoTextAdapter extends CursorAdapter implements
            android.widget.AdapterView.OnItemClickListener {

        private AutoCompleteDbAdapter mDbHelper;

        public ItemAutoTextAdapter(AutoCompleteDbAdapter dbHelper) {
            // Call the CursorAdapter constructor with a null Cursor.
            super(FindMePlace.this, null);
            mDbHelper = dbHelper;
        }
//------------------------------------------------------------------------------------
        @Override
        public Cursor runQueryOnBackgroundThread(CharSequence constraint) {
            if (getFilterQueryProvider() != null) {
                return getFilterQueryProvider().runQuery(constraint);
            }

            Cursor cursor = mDbHelper
                    .getMatchingFromLocation((constraint != null ? constraint
                            .toString() : null));

            return cursor;
        }

        @Override
        public String convertToString(Cursor cursor) {
            //ubah name table name
            final int columnIndex = cursor.getColumnIndexOrThrow("FromLocation");
            final String str = cursor.getString(columnIndex);
            return str;
        }

        @Override
        public void bindView(View view, Context context, Cursor cursor) {
            /*final String text = convertToString(cursor);
            ((TextView) view).setText(text);*/
            final int fromColumnIndex = cursor.getColumnIndexOrThrow("FromLocation");
            final int toColumnIndex = cursor.getColumnIndexOrThrow("ToDestination");
            TextView text1 = (TextView) view.findViewById(R.id.text1);
            text1.setText(cursor.getString(fromColumnIndex));
            TextView text2 = (TextView) view.findViewById(R.id.text1);
            text2.setText(cursor.getString(toColumnIndex));
        }

        @Override
        public View newView(Context context, Cursor cursor, ViewGroup parent) {
            final LayoutInflater inflater = LayoutInflater.from(context);
            //final View view = inflater.inflate(android.R.layout.simple_dropdown_item_1line, parent, false);
            final View view = inflater.inflate(R.layout.list_item, parent, false);
            return view;
        }
//-------------------------------------------------------------------------------------------
        @Override
        public void onItemClick(AdapterView<?> listView, View view,
                int position, long id) {
            // Get the cursor, positioned to the corresponding row in the result
            // set
            Cursor cursor = (Cursor) listView.getItemAtPosition(position);

            // Get the state's capital from this row in the database.
             //**kene ubah*************capital nama database
            String fromLocation = cursor.getString(cursor.getColumnIndexOrThrow("FromLocation"));
            String toDestination = cursor.getString(cursor.getColumnIndexOrThrow("ToDestination"));

            // Update the parent class's TextView
            //mStateCapitalView.setText(fromLocation);
            fromLocation.setText("");
        }
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.find_me_place);
        AutoCompleteDbAdapter dbHelper = new AutoCompleteDbAdapter(this);
        dbHelper.open();

        fromLocation = (AutoCompleteTextView) findViewById(R.id.locationTxt);
        toDestination = (AutoCompleteTextView) findViewById(R.id.destinationTxt);
        search = (Button) findViewById(R.id.button1);

         ItemAutoTextAdapter adapter = this.new ItemAutoTextAdapter(dbHelper);
         fromLocation.setAdapter(adapter);
         fromLocation.setOnItemClickListener(adapter);
         toDestination.setAdapter(adapter);
         toDestination.setOnItemClickListener(adapter);

         /*AutoCompleteTextView fromLocation = (AutoCompleteTextView) findViewById(R.id.locationTxt);
         ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(this, R.layout.country_list, COUNTRIES);
         fromLocation.setAdapter(arrayAdapter); */

         search.setOnClickListener(new View.OnClickListener() {
            public void onClick(View view) {
                setResult(RESULT_OK);
                finish();
            }
        });
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.find_me_place, menu);
        return true;
    }

}
package com.example.series1;
导入android.os.Bundle;
导入android.app.Activity;
导入android.content.Context;
导入android.database.Cursor;
导入android.view.LayoutInflater;
导入android.view.Menu;
导入android.view.view;
导入android.view.ViewGroup;
导入android.widget.AdapterView;
导入android.widget.ArrayAdapter;
导入android.widget.AutoCompleteTextView;
导入android.widget.Button;
导入android.widget.CursorAdapter;
导入android.widget.TextView;
公共类FindReplace扩展活动{
专用自动完成的备份器MDB帮助器;
从位置到目标的私有自动完成文本视图;
按钮搜索;
类ItemAutoTextAdapter扩展了CursorAdapter实现
android.widget.AdapterView.OnItemClickListener{
专用自动完成的备份器MDB帮助器;
公共项AutoTextAdapter(AutoCompleteDbAdapter dbHelper){
//使用空游标调用CursorAdapter构造函数。
super(FindMePlace.this,null);
mDbHelper=dbHelper;
}
//------------------------------------------------------------------------------------
@凌驾
公共游标runQueryOnBackgroundThread(CharSequence约束){
if(getFilterQueryProvider()!=null){
返回getFilterQueryProvider().runQuery(约束);
}
游标=MDB帮助器
.getMatchingFromLocation((约束!=null)约束
.toString():null));
返回光标;
}
@凌驾
公共字符串convertToString(游标){
//ubah名称表名
final int columnIndex=cursor.getColumnIndexOrThrow(“FromLocation”);
最终字符串str=cursor.getString(columnIndex);
返回str;
}
@凌驾
公共void bindView(视图、上下文上下文、光标){
/*最终字符串文本=convertToString(光标);
((文本视图)视图).setText(文本)*/
final int fromColumnIndex=cursor.getColumnIndexOrThrow(“FromLocation”);
final int to columnIndex=cursor.getColumnIndexOrThrow(“ToDestination”);
TextView text1=(TextView)view.findViewById(R.id.text1);
text1.setText(cursor.getString(fromColumnIndex));
TextView text2=(TextView)view.findViewById(R.id.text1);
text2.setText(cursor.getString(tocolumnidex));
}
@凌驾
公共视图newView(上下文上下文、光标、视图组父对象){
最终LayoutFlater充气机=LayoutFlater.from(上下文);
//最终视图=充气机。充气(android.R.layout.simple\u下拉列表\u item\u 1line,父项,false);
最终视图=充气机充气(R.layout.list\u项,父项,false);
返回视图;
}
//-------------------------------------------------------------------------------------------
@凌驾
public void onItemClick(AdapterView列表视图、视图、,
内部位置,长id){
//获取光标,定位到结果中的相应行
//设置
游标游标=(游标)listView.getItemAtPosition(位置);
//从数据库中的此行获取州的资本。
//**kene ubah**********资本nama数据库
String fromLocation=cursor.getString(cursor.getColumnIndexOrThrow(“fromLocation”);
String toDestination=cursor.getString(cursor.getColumnIndexOrThrow(“toDestination”);
//更新父类的TextView
//mStateCapitalView.setText(fromLocation);
fromLocation.setText(“”);
}
}
@凌驾
创建时受保护的void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.find_me_place);
AutoCompleteDbAdapter dbHelper=新的AutoCompleteDbAdapter(此);
dbHelper.open();
fromLocation=(AutoCompleteTextView)findViewById(R.id.locationTxt);
toDestination=(AutoCompleteTextView)findViewById(R.id.DestinationText);
搜索=(按钮)findViewById(R.id.button1);
ItemAutoTextAdapter=this.new ItemAutoTextAdapter(dbHelper);
setAdapter(适配器);
setOnItemClickListener(适配器);
toDestination.setAdapter(适配器);
toDestination.setOnItemClickListener(适配器);
/*AutoCompleteTextView fromLocation=(AutoCompleteTextView)findViewById(R.id.locationTxt);
ArrayAdapter ArrayAdapter=新的ArrayAdapter(此,R.layout.country_列表,国家);
设置适配器(arrayAdapter)*/
search.setOnClickListener(新视图.OnClickListener(){
公共void onClick(视图){
设置结果(结果\正常);
完成();
}
});
}
@凌驾
公共布尔onCreateOptions菜单(菜单){
//为菜单充气;这会将项目添加到操作栏(如果存在)。
getMenuInflater().充气(R.menu.find\u me\u place,menu);
返回true;
}
}
fromLocation
是一个字符串实例。String类没有
setText()
方法。您想要使用
fromLocation=“
”设置字符串值,或者想要设置“fr”的文本