列表视图和适配器不起作用

时间:2018-04-18 15:15:31

标签: java android firebase listview adapter

我的列表视图遇到问题。当我不使用它我的应用程序工作,但当我添加它,我有问题,我没有看到我的选项卡。我找不到解决方案。对不起,我是Android Studio的初学者。如果有人可以帮助我,我会很感激!

Button button_friend_request;
EditText request_email;
ConstraintLayout activity_friend;
ListView friend_list;
private ArrayList<String> arrayList;
private ArrayAdapter<String> adapter;

FirebaseAuth auth;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_friends);
    super.onCreateDrawer();

    auth = FirebaseAuth.getInstance();

    request_email = (EditText) findViewById(R.id.request_email);
    button_friend_request = (Button) findViewById(R.id.send_friend_request);
    activity_friend = (ConstraintLayout) findViewById(R.id.activity_friend);
    friend_list = (ListView)findViewById(R.id.list_friend);

    String[] names = {"John"};
    arrayList = new ArrayList<>(Arrays.asList(names));
    adapter = new ArrayAdapter<String>(this,R.layout.list_friend,R.id.request_email,arrayList);
    friend_list.setAdapter(adapter);

    button_friend_request.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            String email = request_email.getText().toString();

            sendRequest(email);

        }

    });
}

private void sendRequest(final String email) {
    auth.sendSignInLinkToEmail(email, ActionCodeSettings.newBuilder().build()).addOnCompleteListener(new OnCompleteListener<Void>() {
        @Override
        public void onComplete(@NonNull Task<Void> task) {
            if (task.isSuccessful())
            {
                Snackbar snackbar = Snackbar.make(activity_friend,"Successful send request to email :" + email,Snackbar.LENGTH_LONG);
                snackbar.show();

                arrayList.add(email);

                adapter.notifyDataSetChanged();
            }
            else
            {
                Snackbar snackbar = Snackbar.make(activity_friend,"Failed to send email.", Snackbar.LENGTH_LONG);
                snackbar.show();
            }

        }
    });

}

I want something like this, with emails

1 个答案:

答案 0 :(得分:0)

您也应该将电子邮件添加到适配器。

   adapter.add(email);
   adapter.notifyDataSetChanged();

抱歉,我没有得到你错过标签的意思。

希望上面的修复可以帮到你