Java 无法解析方法';getStringArrayList';当我';我正在为Listview制作一个搜索过滤器
我是一个初学者,我正在创建一个求职应用程序,它将求职信息显示为listview,其中的数据来自WAMP服务器数据库。我遇到了一个问题:在为此Listview创建搜索筛选器时,无法解析方法“getStringArrayList”。请参阅SearchFilter.java的第11行。有人能帮忙吗?多谢各位 SearchFilter.javaJava 无法解析方法';getStringArrayList';当我';我正在为Listview制作一个搜索过滤器,java,php,android,listview,arraylist,Java,Php,Android,Listview,Arraylist,我是一个初学者,我正在创建一个求职应用程序,它将求职信息显示为listview,其中的数据来自WAMP服务器数据库。我遇到了一个问题:在为此Listview创建搜索筛选器时,无法解析方法“getStringArrayList”。请参阅SearchFilter.java的第11行。有人能帮忙吗?多谢各位 SearchFilter.java public class SearchFilter extends ListActivity { private EditText filterText = n
public class SearchFilter extends ListActivity {
private EditText filterText = null;
ArrayAdapter<String> adapter = null;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
filterText = (EditText) findViewById(R.id.search_box);
filterText.addTextChangedListener(filterTextWatcher);
setListAdapter(new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1,
getStringArrayList())); ***<<<<< this line !***
}
private TextWatcher filterTextWatcher = new TextWatcher() {
public void afterTextChanged(Editable s) {
}
public void beforeTextChanged(CharSequence s, int start, int count,
int after) {
}
public void onTextChanged(CharSequence s, int start, int before,
int count) {
adapter.getFilter().filter(s);
}
};
@Override
protected void onDestroy() {
super.onDestroy();
filterText.removeTextChangedListener(filterTextWatcher);
}
}
公共类SearchFilter扩展了ListActivity{
private EditText filterText=null;
ArrayAdapter适配器=空;
@凌驾
创建时受保护的void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
filterText=(EditText)findViewById(R.id.search_框);
filterText.addTextChangedListener(filterTextWatcher);
setListAdapter(新阵列适配器)(此,
android.R.layout.simple\u list\u item\u 1,
getStringArrayList());***getStringArrayList
是Bundle(如savedInstanceState)上的一个方法。活动中没有此类方法。希望对您有所帮助
目前,您的信息列表是ArrayList>,很难直接传递给活动。因此,请找到一种将其表示为ArrayList的方法,或者找到由Intent的putExtra方法支持的更合适的数据类型。下面是使用ArrayList的建议解决方案
将数据按意图传递到活动中可以让您将其返回到SearchFilter中。在调用活动中,输入以下内容:
Intent i = new Intent(this, SearchFilter.class);
i.putStringArrayListExtra("com.yourpackagename.here.keynamehere", aStringArrayList);
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
filterText = (EditText) findViewById(R.id.search_box);
filterText.addTextChangedListener(filterTextWatcher);
Intent startingIntent = getIntent();
ArrayList<String> arrayList = new ArrayList<String>();
if (startingIntent != null) {
arrayList = startingIntent.getStringArrayList("com.yourpackagename.here.keynamehere");
}
setListAdapter(new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1,
arrayList));
}
在SearchFilter.java中,放置如下内容:
Intent i = new Intent(this, SearchFilter.class);
i.putStringArrayListExtra("com.yourpackagename.here.keynamehere", aStringArrayList);
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
filterText = (EditText) findViewById(R.id.search_box);
filterText.addTextChangedListener(filterTextWatcher);
Intent startingIntent = getIntent();
ArrayList<String> arrayList = new ArrayList<String>();
if (startingIntent != null) {
arrayList = startingIntent.getStringArrayList("com.yourpackagename.here.keynamehere");
}
setListAdapter(new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1,
arrayList));
}
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
filterText=(EditText)findViewById(R.id.search_框);
filterText.addTextChangedListener(filterTextWatcher);
Intent startingIntent=getIntent();
ArrayList ArrayList=新的ArrayList();
if(startingIntent!=null){
arrayList=startingIntent.getStringArrayList(“com.yourpackagename.here.keynamehere”);
}
setListAdapter(新阵列适配器)(此,
android.R.layout.simple\u list\u item\u 1,
arrayList);
}
谢谢你的帮助。我想知道我能做些什么才能让它工作?告诉问题是好的,但还不够,你也应该提出解决方案。@尼斯曼,解决方案是不要调用不存在的方法。没有明确说明预期的行为,因为这基本上是一个调试问题。不过,我会的用一些建议更新我的答案,因为卡尔文问得很好。