无法解析构造函数ArrayAdapter(saveourcar.soc.Insurance、int、int、java.lang.String[],java.lang.Integer[])
我制作了一个应用程序,其中包含使用无法解析构造函数ArrayAdapter(saveourcar.soc.Insurance、int、int、java.lang.String[],java.lang.Integer[]),java,android,android-studio,android-arrayadapter,android-search,Java,Android,Android Studio,Android Arrayadapter,Android Search,我制作了一个应用程序,其中包含使用列表视图的保险公司列表。使用数组填充列表视图。我目前可以使用筛选器搜索此列表。但是,在列表视图中的每个项目旁边我想要一个图像,我可以使用CustomListAdapter adapter=new CustomListAdapter(this,itemname,imgid)但是这会阻止我的搜索工作,所以我尝试像这样实现它adapter=newarrayadapter(this,R.layout.mylist,R.id.textView1,itemname,imgi
列表视图的保险公司列表
。使用数组填充列表视图
。我目前可以使用筛选器搜索此列表。但是,在列表视图中的每个项目旁边
我想要一个图像,我可以使用CustomListAdapter adapter=new CustomListAdapter(this,itemname,imgid)代码>但是这会阻止我的搜索工作,所以我尝试像这样实现它adapter=newarrayadapter(this,R.layout.mylist,R.id.textView1,itemname,imgid)然后抛出的code>无法解析构造函数ArrayAdapter(saveourcar.soc.Insurance,int,int,java.lang.String[],java.lang.Integer[])
错误。我是否可以将我的imgid
包含在我的ArrayAdapter
中
我的代码是fallows
Insurance.java
public class Insurance extends AppCompatActivity {
ListView list;
ArrayList<String> listItems;
ArrayAdapter<String> adapter;
EditText inputSearch;
String[] itemname ={
"123.ie",
"AA",
"Acorn",
"Admiral",
"AIG",
"Allianz",
"Aviva",
"Auto Direct",
"AXA",
"Chill",
"Churchill",
"CoverBox",
"DirectChoice",
"FBD",
};
Integer[] imgid= {
R.drawable.onetwothree,
R.drawable.aa,
R.drawable.acorn,
R.drawable.admiral,
R.drawable.aig,
R.drawable.allianz,
R.drawable.aviva,
R.drawable.autodirect,
R.drawable.axa,
R.drawable.chill,
R.drawable.churchill,
R.drawable.coverbox,
R.drawable.directchoice,
R.drawable.fbd,
};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_insurance);
adapter = new ArrayAdapter<String>(this, R.layout.mylist, R.id.textView1, itemname, imgid);
CustomListAdapter adapter=new CustomListAdapter(this, itemname, imgid);
list=(ListView)findViewById(R.id.list);
inputSearch = (EditText) findViewById(R.id.itemtext);
list.setAdapter(adapter);
inputSearch.addTextChangedListener(new TextWatcher() {
@Override
public void onTextChanged(CharSequence cs, int arg1, int arg2, int arg3) {
// When user changed the Text
Insurance.this.adapter.getFilter().filter(cs);
}
@Override
public void beforeTextChanged(CharSequence arg0, int arg1, int arg2,
int arg3) {
// TODO Auto-generated method stub
}
@Override
public void afterTextChanged(Editable arg0) {
// TODO Auto-generated method stub
}
});
您应该使用CustomListAdapter
,因为您需要在每行中显示名称和图像。要简化此操作,您应该做的一件事是将图像和名称合并到单个对象中,并更新CustomListAdapter
,以使用该新对象的列表,而不是两个单独的数组。否则,您将不得不编写一个自定义过滤器并自己过滤这两个数组
另外,在返回名称的新对象上创建一个toString()
方法。默认情况下,ArrayAdapter
过滤器将您输入的字符串与每个对象的toString()
进行比较,以了解要保留哪些记录以及要过滤掉哪些记录。这将修复CustomListAdapter
上的过滤ArrayAdapter
的基本实现只支持非常有限的带有TextView
的布局。您实现自定义适配器是正确的,筛选仍应在其上工作。你可以添加过滤代码,看看我们是否能发现任何问题。我尝试过用我的自定义适配器进行过滤,它似乎不起作用,除非我做得不对,但我看不出如何。有没有关于如何使用自定义适配器进行此操作的想法。什么意思似乎不起作用?它目前在做什么?你可以在线搜索一个示例或查看另一个Q/A,关于我尝试使用我的自定义适配器进行过滤,但它没有过滤我试图添加到R.id.layout.mylist
中的列表,然后我得到一个错误,不确定我做错了什么,正如我提到的,你可以在帖子中添加自定义适配器的代码,以便我们可以尝试然后找出你做错了什么。碰巧我回到我们的聊天中,看到了你最后的评论。只是为了让您知道,当新消息发布到那里时,不会通知用户。最好在这里留下评论,以便我得到通知。如果你再打开聊天室,我会回答你最近的问题。如果您还有其他问题,请告诉我。
<EditText
android:layout_width="400dp"
android:layout_height="60dp"
android:id="@+id/itemtext"
android:layout_marginBottom="50dp"
/>
<ListView
android:id="@+id/list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginTop="107dp">
</ListView>
<LinearLayout
android:layout_width="0dp"
android:layout_height="60dp"
android:layout_weight="2"
>
<ImageView
android:id="@+id/icon"
android:layout_width="60dp"
android:layout_height="60dp"
android:padding="5dp"
/>
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="6"
android:orientation="vertical" >
<TextView
android:id="@+id/item"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginTop="5dp"
android:padding="2dp"
android:text="Medium Text"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#FFFFFF"
/>
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:text="TextView"
/>
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="1"
android:orientation="vertical"
>
<ImageView
android:id="@+id/imageView2"
android:layout_width="20dp"
android:layout_height="50dp"
android:layout_alignParentRight="true"
android:src="@drawable/nextarrow"
android:layout_marginTop="6dp" />
Error:(67, 35) error: constructor CustomListAdapter in class CustomListAdapter cannot be applied to given types;
required: Activity,String[],Integer[]
found: Insurance,String[],Integer[],int
reason: actual and formal argument lists differ in length