2016-06-07 52 views
1

這裏是我的自定義列表適配器Canot解決方法 '超(android.content.context,INT,INT,java.util.ArrayList中的<android.Bluetooth.Bluetoothdevices>)'

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; 
    } 
} 

我傳遞一個bluetoothdevices的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)); 

幫助PLE問題ASE!

+0

類型參數解決問題'BluetoothDevice',而不是'ArrayList '。也就是說,'...擴展了ArrayAdapter '。 –

+0

從MyAdapter構造器中刪除'super(context,resource,textViewResourceId,objects);' – SaravInfern

回答

1

嘗試改變這種

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

這個

private class MyAdapter extends ArrayAdapter<BluetoothDevice> { 

取出ArrayList部分。這隻需要一個元素將要處理的數據類型。

+0

你是對的我只是做了同樣的Thanku –

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; 
    } 
} 
+0

但是我在這條線上獲得RED行 super(context,resource,textViewResourceId,objects); –

1

我只是更換

private class MyAdapter extends ArrayAdapter<ArrayList<BluetoothDevice>> 

private class MyAdapter<BluetoothDevice> extends ArrayAdapter<BluetoothDevice> 

Thanku :)在`MyAdapter`的報關行應該只是對`ArrayAdapter`

相關問題