Canot解析方法'super(android.content.context,int,int,java.util.arraylist <android.bluetooth.bluetoothdevices>)'

时间:2016-06-07 04:40:51

标签: android listview arraylist bluetooth

这是我的自定义列表适配器

private class MyAdapter extends ArrayAdapter<ArrayList<BluetoothDevice>> {

    ArrayList<BluetoothDevice> data;
    Context context;

    public MyAdapter(Context context, int resource, int textViewResourceId, ArrayList<BluetoothDevice> objects) {
        super(context, resource, textViewResourceId,objects);
        this.context=context;
        this.data=objects;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        View v=getLayoutInflater().inflate(R.layout.row,parent,false);

        TextView textView=(TextView)findViewById(R.id.row_textview);

        BluetoothDevice device=data.get(position);

        textView.setText(device.getName()+"");



        return v;
    }
}

我正在传递一个蓝牙设备的arraylist构造函数causig问题

Canot resolve method 'super(android.content.context,int,int,java.util.arraylist<android.Bluetooth.Bluetoothdevices>)'

这里我正在设置适配器

listView.setAdapter(new MyAdapter(getApplicationContext(),R.layout.row,R.id.row_textview,bluetoothDeviceArrayList));

请帮助!

3 个答案:

答案 0 :(得分:1)

尝试更改此

  private class MyAdapter extends ArrayAdapter<ArrayList<BluetoothDevice>> {

到这个

  private class MyAdapter extends ArrayAdapter<BluetoothDevice> {

删除ArrayList部分。这只需要一个元素将要处理的数据类型。

答案 1 :(得分:1)

我只是通过替换来解决问题

private class MyAdapter extends ArrayAdapter<ArrayList<BluetoothDevice>>

 private class MyAdapter<BluetoothDevice> extends ArrayAdapter<BluetoothDevice>

感谢:))

答案 2 :(得分:0)

只是你的例子

public class UsersAdapter extends ArrayAdapter<User> {
        public UsersAdapter(Context context, ArrayList<User> users) {
           super(context, 0, users);
        }

        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
           // Get the data item for this position
           User user = getItem(position);    
           // Check if an existing view is being reused, otherwise inflate the view
           if (convertView == null) {
              convertView = LayoutInflater.from(getContext()).inflate(R.layout.item_user, parent, false);
           }
           // Lookup view for data population
           TextView tvName = (TextView) convertView.findViewById(R.id.tvName);
           TextView tvHome = (TextView) convertView.findViewById(R.id.tvHome);
           // Populate the data into the template view using the data object
           tvName.setText(user.name);
           tvHome.setText(user.hometown);
           // Return the completed view to render on screen
           return convertView;
       }
    }

xml文件

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
 android:layout_width="match_parent"
 android:layout_height="match_parent" >
    <TextView
      android:id="@+id/tvName"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:text="Name" />
   <TextView
      android:id="@+id/tvHome"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:text="HomeTown" />
</LinearLayout>

模型类

public class User {
    public String name;
    public String hometown;

    public User(String name, String hometown) {
       this.name = name;
       this.hometown = hometown;
    }
}