カスタムリストアダプターの作成方法についてはhttps://github.com/codepath/android_guides/wiki/Using-an-ArrayAdapter-with-ListView#using-a-custom-arrayadapterを使用しています。しかし、エラーがここに表示されます(RegisterAccountクラスでこのコード)Androidリストアダプター非静的メソッドadd(T)は静的コンテキストから参照できません
- 。しかし、私は私はShop shop = new Shop (uid, name, address,email); listadapter.add(shop);
<によってアダプタにデータを追加しようと、「非静的メソッド(T)を追加」の問題を得ました
は、それは私のlistAdapterクラス
public class shopListAdapter extends ArrayAdapter<Shop> {
public shopListAdapter(Context context, ArrayList<Shop> shops) {
super(context, 0, shops);
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
Shop shop = getItem(position);
if (convertView == null) {
convertView = LayoutInflater.from(getContext()).inflate(R.layout.item, parent, false);
}
TextView name = (TextView) convertView.findViewById(R.id.nameTV);
TextView address = (TextView) convertView.findViewById(R.id.addressTV);
name.setText(shop.getShopName());
address.setText(shop.getAddress());
return convertView;
}
}
モデル
public Shop(String shopID, String name, String address, String email){
this.shopID = shopID;
this.name = name;
this.address = address;
this.email = email;
}
public void setShopID(String shopID) {
this.shopID = shopID;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public void setAddress(String address) {
this.address = address;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
です(断片で)
活動
private void initAdapter(){
ArrayList<Shop> arrayshop = new ArrayList<Shop>();
shopListAdapter adapter = new shopListAdapter(getActivity(), arrayshop);
listView.setAdapter(adapter);
}
RegisterAccount
mAuth = FirebaseAuth.getInstance();
mProgress = new ProgressDialog(this);
businessAccount = FirebaseDatabase.getInstance().getReference().child("businessAcc");
protected void startSetupAccount() {
final String address = addressTF.getText().toString().trim();
final String name = mNameField.getText().toString().trim();
final String user_id = mAuth.getCurrentUser().getUid();
final String email = mAuth.getCurrentUser().getEmail();
businessAccount.child(user_id).child("uid").setValue(user_id);
businessAccount.child(user_id).child("username").setValue(name);
businessAccount.child(user_id).child("address").setValue(address);
businessAccount.child(user_id).child("email").setValue(email);
Shop shop = new Shop(uid,name,address,email);
//shopListAdapter.add(shop);
mProgress.dismiss();
}
});
}
}
カスタムアダプターはHairShopを受け入れますが、ショップを追加している間は、 –
Register Registerコード... –
編集済み申し訳ありません.... – kings077712