Codes to improve firebase chatting app in sketchware

Here are a few codes which can be used in the chat application created using Firebase in Sketchware.

1. Remove divider​ height of ListView
To remove the divider height of ListView displaying messages, put following code in onCreate, in an add source directly block.
listview1.setDivider(null);
listview1.setDividerHeight(0);

2. Display end of ListView on refresh
To make the ListView scroll to display the last element of list when updated, put following code in onCreate, in an add source directly block.
listview1.setTranscriptMode(ListView.TRANSCRIPT_MODE_ALWAYS_SCROLL);
listview1.setStackFromBottom(true);

3. Set width of ListView items to 3/4 of screen width
Firstly, in CustomView, insert a LinearH linear1, and inside that insert a LinearV linear2. Put all contents to be displayed in linear2.

Now, in event onBindCustomView, add a number variable width. Set width to getDisplayWidthPixels * 0.75, and set it as width of linear2 using following code.
LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams((int)width, LinearLayout.LayoutParams.WRAP_CONTENT);
linear2.setLayoutParams(lp);


4. Rounded corners and Custom background color
In onBindCustomView event, add a add source directly block and put code to create a GradientDrawable with custom background color and rounded corners, as given below, and set it as background of linear2.
android.graphics.drawable.GradientDrawable gd = new android.graphics.drawable.GradientDrawable();
gd.setColor(Color.parseColor("#ffffff"));
gd.setCornerRadius(60);
linear2.setBackground(gd);

5. Display messages of device user on right and those of others on left.
To display messages of user on right and those of others on left, in onBindCustomView event, use blocks as shown in image above. The code used is:
If File user getData key username equals (get value at position key name of List Map map1) then,
linear1.setGravity(Gravity.RIGHT);
else,
linear1.setGravity(Gravity.LEFT);


6. Hide Keyboard on button click
Add following code in on button click event.
android.view.inputmethod.InputMethodManager imm = (android.view.inputmethod.InputMethodManager)getSystemService(INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(getCurrentFocus().getWindowToken(), 0);

To understand more watch the video below.

Comments

  1. How to load image from url in listview

    ReplyDelete
  2. Great job. Is it possible make push notifications?

    ReplyDelete
  3. Nice blog........ thanks for this...... App In Minute provides you the platform that you seek for creating your online store. With App In Minute’s help, you can develop your Android Application & Website for free and display your products or services to the world. App in minute can create a free business portfolio app or a gallery app with App In Minute Tool. For more information visit on https://www.appinminute.com/

    ReplyDelete
    Replies
    1. Fuck you and your spam mate. Take that shit somewhere else. Don't spam on a person's hard work, dickwad.

      Delete
  4. This comment has been removed by the author.

    ReplyDelete
  5. Hi Sanjeev,
    How can we get the current location of the device (GPS)?
    THANKS!

    ReplyDelete
  6. A questão da ListView quando atualiza a lista ela rola automaticamente para baixo, tem como fazer ela atualizar mais manter a tela na mesma posição? Desde já agradeço

    ReplyDelete
  7. Is it necessary to upload the app to play store? Isn't it possible that two people download it from sketchware only?

    ReplyDelete
    Replies
    1. You can send the apk file to your friend, no need to upload to play store

      Delete
  8. How to add chat rooms in chatting App?

    ReplyDelete
  9. How to make notification of this chat app?

    ReplyDelete
  10. This comment has been removed by the author.

    ReplyDelete
  11. Guys what will be happening if my app doesn't open if I send it to another user with android 8.0 mobile phone and the app doesn't open . .it says app not installed

    ReplyDelete
  12. Visit my blog perfect Login With Email Verification https://sketchwarehelptech.blogspot.com/2019/09/perfect-login-with-email-verification.html

    ReplyDelete
  13. Can you make a chat app where you chat with friends? If you have their numbers like WhatsApp.

    ReplyDelete

Post a Comment

Popular posts from this blog

A Flash Light App in Sketchware

Create Music Player app in Sketchware

Simple car racing android game in Sketchware

In Sketchware: How to create a calculator for any simple formula?

Firebase auth in Sketchware for Login Activity