我有一个疑问。我有一个包含autocompletetextview的活动.autoocompletetextview的内容已在strings.xml文件中声明为字符串数组。我在strings.xml文件中还有一个字符串数组。我想要什么就是当我从autocompletetextview中选择一个项目时,它应该以toast的形式从第二个字符串数组中显示一个值。这是可能的.Plz帮帮我
答案 0 :(得分:1)
适用于Array ::
String[] myarray =getResources().getStringArray(R.array.array);
For String ::
String myString =getResources().getString(R.string.str);
答案 1 :(得分:0)
检查,
package mytest.projects;
import android.app.ListActivity;
import android.os.Bundle;
import android.widget.ArrayAdapter;
public class example extends ListActivity {
String[] mTestArray;
/** Called when the activity is first created. */
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Create an ArrayAdapter that will contain all list items
ArrayAdapter<String> adapter;
mTestArray = = getResources().getStringArray(R.array.testArray);
/* Assign the name array to that adapter and
also choose a simple layout for the list items */
adapter = new ArrayAdapter<String>(
this,
android.R.layout.simple_list_item_1,
mTestArray);
// Assign the adapter to this ListActivity
setListAdapter(adapter);
}
}