我正在与AutoCompleteTextView
挣扎。类训练调用类getAddress,其中包含几个功能正常的editText和有效的微调器。 AutoCompleteTextView
未列出我的数组中的项目。这是我的文件:
address_list.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout android:id="@+id/LinearLayout01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
xmlns:android="http://schemas.android.com/apk/res/android">
<ListView android:id="@+id/ListView01"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:background="#B0B0B0" />
<EditText android:id="@+id/editAddressControl" android:text="" android:maxLength="4"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:inputType="number"
android:imeOptions="actionDone"
android:layout_toRightOf="@+id/editAddressText"
android:drawSelectorOnTop="true"
android:visibility="invisible" ></EditText>
<TextView android:id="@+id/editAddressText" android:text="Enter Locomotive Address"
android:textSize="20sp"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:drawSelectorOnTop="true"
android:layout_marginTop="8dip"
android:visibility="invisible"></TextView>
<TextView android:id="@+id/manufacturerText" android:text="Manufacturer"
android:textSize="20sp"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:drawSelectorOnTop="true"
android:layout_marginTop="8dip"
android:layout_below="@+id/editAddressControl"
android:visibility="visible"></TextView>
<Spinner android:id="@+id/manufacturerSpinner" android:prompt="@string/manufacturerPrompt"
android:layout_width="wrap_content" android:layout_height="40dip"
android:drawSelectorOnTop="true"
android:layout_toRightOf="@+id/manufacturerText"
android:layout_below="@+id/editAddressControl"
android:visibility="visible"></Spinner>
<TextView android:id="@+id/roadNameText" android:text="Road Name"
android:textSize="20sp"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:drawSelectorOnTop="true"
android:layout_marginTop="8dip"
android:layout_below="@+id/manufacturerText"
android:visibility="visible"></TextView>
<AutoCompleteTextView
android:id="@+id/autoCompleteRoadNames" android:text=""
android:layout_width="wrap_content" android:layout_height="40dip"
android:textSize="20sp" android:visibility="visible"
android:layout_below="@+id/manufacturerSpinner"
android:completionThreshold="1"
android:layout_marginLeft="124dip"
></AutoCompleteTextView>
<Button android:id="@+id/delete" android:text="Delete Address?"
android:layout_height="wrap_content" android:layout_width="wrap_content"
android:layout_alignParentRight="true"
android:visibility="invisible" ></Button>
<Button android:id="@+id/edit" android:text="Edit Address?"
android:layout_height="wrap_content" android:layout_width="wrap_content"
android:layout_alignParentLeft="true"
android:visibility="invisible" ></Button>
</RelativeLayout>
这是 getAddress
类public class getAddress extends Activity
{
/* Called when the activity is first created. */
private ListView lv1;
private String locomotiveAddress[],locomotiveFx[];
private EditText newAddress;
private TextView newAddressText;
private Button deleteButton, editButton;
private long deleteRow=0;
private boolean editFlag; // used to determine on "DONE' key pressed whether a new address was entered or an edit was done
@Override
public void onCreate(Bundle savedInstanceState)
{
locomotiveFx=new String[13]; // need to keep for rewriting on changes to list
locomotiveAddress=new String[13]; // allow 12 address saved
locomotiveAddress[0]="New Address";
editFlag=false;
// Read from file objectTrains.txt and restore locomotive and manufacturer list
InputStream fHandle;
try
{
fHandle = openFileInput("objectTrains.txt");
InputStreamReader inputreader = new InputStreamReader(fHandle);
BufferedReader buffreader = new BufferedReader(inputreader);
String line="";
int x;
for (x=1; x<13; x++)
{
line = buffreader.readLine();
if (line == null)
{
locomotiveAddress[x]="";
locomotiveFx[x]="";
}
else
{
String[] item = (line).split(","); // array items[] contains comma delimited items in file
locomotiveAddress[x]=("Locomotive "+item[0]+" "+item[1]+" "); // get the first item, or locomotive number
locomotiveFx[x]=(item[2]); // get Function key status
}
}
fHandle.close();
}
catch (FileNotFoundException e2)
{
e2.printStackTrace();
}
catch (IOException e)
{
e.printStackTrace();
}
super.onCreate(savedInstanceState);
setContentView(R.layout.address_list);
/* manufacturer list */
Spinner manufacturer = (Spinner) findViewById(R.id.manufacturerSpinner);
ArrayAdapter<CharSequence> manufactureAdapter = ArrayAdapter.createFromResource(this, R.array.manufacturer, android.R.layout.simple_spinner_item);
manufacturer.setAdapter(manufactureAdapter);
/* road name list */
findViewById(R.id.autoCompleteRoadNames);
R.layout.list_item, locoNames);
AutoCompleteTextView acTextView = (AutoCompleteTextView)
findViewById(R.id.autoCompleteRoadNames);
ArrayAdapter roadNamesAdapter = new ArrayAdapter(this, android.R.layout.simple_dropdown_item_1line, locoNames);
android.R.layout.simple_dropdown_item_1line, locoNames);
acTextView.setThreshold(3);
acTextView.setAdapter(roadNamesAdapter);
R.array.roadNames, android.R.layout.simple_spinner_item);
static final String[] locoNames = new String[]{
"This is the first line that is too long and it needs to wrap content",
"Albania", "Algeria", "American Samoa", "Andorra",
"zawer",
"Bahrain", "Bangladesh", "Barbados", "Belarus", "Belgium"
};
locoNames已经在几个不同的地方声明了几种不同的方式。任何想法都会受到欢迎。谢谢!