Emoji Icon is showing Strange Letters in TextView - android

I know this questions already has been asked by some peoples but Still I am getting issue fro last 1 day. I have chat application and My emoji is sent successfully and displaying perfect in Website but In TextView its returning strange characters. I am using this Library for Emoji in TextView
This is Response from Web
data
:
"{"type":"text","message":"\ud83d\ude29","to":"264","from":"175","group_id":"0","groupFlag":0}"
but My TextView showing this Value
ðÿ˜ðÿ˜¡ðÿ˜¡ðÿ˜¡
**My ScreenShot is Here **
Please guide me How can I show Emoji in TextView. ? My complete code is
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
rootView = findViewById(R.id.root_view);
emojiButton = (ImageView) findViewById(R.id.emoji_btn);
submitButton = (ImageView) findViewById(R.id.submit_btn);
emojiconEditText = (EmojiconEditText) findViewById(R.id.emojicon_edit_text);
textView = (EmojiconTextView) findViewById(R.id.textView);
emojIcon = new EmojIconActions(this, rootView, emojiconEditText, emojiButton);
emojIcon.ShowEmojIcon();
emojIcon.setKeyboardListener(new EmojIconActions.KeyboardListener() {
#Override
public void onKeyboardOpen() {
Log.e("Keyboard", "open");
}
#Override
public void onKeyboardClose() {
Log.e("Keyboard", "close");
}
});
submitButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
String newText = emojiconEditText.getText().toString();
textView.setText(newText);
}
});
}

can you try this may be worked:
emojIcon.setUseSystemEmoji(true);

Perhaps you need you need to convert the Html request to string
Html.fromHtml((String) YOUR_STRING_HERE).toString()

Related

can i know pls the INPUT variable why it's giving me error always, thank you so much

can i know pls why the input variable why it's giving me error always, thank you so much.
This is my code below:
public class MainActivity extends AppCompatActivity {
public TextView textView;
public EditText editText;
public Button btn;
public int input;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
textView=findViewById(R.id.textView);
editText = findViewById(R.id.editText);
btn = findViewById(R.id.btn);
` input= Integer.parseInt(editText.getText().toString());`
btn.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
textView.setText(input );
}
});
}
}
The error is happening as the String cant be cast to an integer. This could be because your editText is empty or that you have characters that are not integers in there (E.g. Letters). Therefor you should use try and catch to catch the error.
Currently you are trying to parse the input string from editText in onCreate() as soon as the view is created. This will try to parse the default text associated with the editText. I think what you want is to parse the input at the time of clicking button. In that case move the input parsing code inside onClick(). Also it is better to catch NumberFormatException when calling parseInt() if you cannot guarantee that the text entered in the EditText is always an integer.
#Override
public void onClick(View v) {
android.util.Log.i("MyActivity", "onClick: edit text = " + editText.getText());
input= Integer.parseInt(editText.getText().toString());
textView.setText(input );
}

Progress Bar not showing in screen but showing in debugger

I am adding a Progress Bar when the user does a search query, and it will not show up in the screen. Here are the snippets:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Button searchButton = (Button) findViewById(R.id.searchButton);
setContentView(R.layout.activity_main); //main layout, which has a child layout called resultsLayout
searchButton.setOnClickListener(new View.OnClickListener(){
#Override
public void onClick(View v){
EditText searchString = (EditText) findViewById(R.id.searchString);
search(searchString.getText().toString());
}
});
protected void search(String searchString){
LinearLayout resultLayout = ((LinearLayout) findViewById(R.id.resultsLayout));
resultLayout.addView(DisplayResults.getLoadBar(getApplicationContext()));
//do search
resultLayout.removeAllViews();
}
public static ProgressBar getLoadBar(Context context){
ProgressBar loadBar = new ProgressBar(context);
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
loadBar.setLayoutParams(params);
loadBar.setVisibility(View.VISIBLE);
return loadBar;
}
I know some of it might not be needed, like the setVisibility right when creating, but I have tried several things and it not works. Perhaps there wasn't enough time to show up the bar?(It takes about 1.5sec for the search)
I have also debugged the application, and it shows the ProgressBar as a child of the layout, but I still cannot see it in the screen.
ProgressDialog progressDialog; //Create a prog dialog object
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Button searchButton = (Button) findViewById(R.id.searchButton);
progressDialog=new ProgressDialog(this); //init it
searchButton.setOnClickListener(new View.OnClickListener(){
#Override
public void onClick(View v){
progressDialog.show(); //show it when needed
EditText searchString = (EditText) findViewById(R.id.searchString);
search(searchString.getText().toString());
}
});
protected void search(String searchString){
progressDialog.dismiss();//dismiss it when the search is complete
LinearLayout resultLayout = ((LinearLayout) findViewById(R.id.resultsLayout));
resultLayout.addView(DisplayResults.getLoadBar(getApplicationContext()));
//do search
resultLayout.removeAllViews();
}
You could try this ProgressDialog object implementation.
https://developer.android.com/reference/android/app/ProgressDialog.html
add setContentView(resultLayout); at the end of search() method
I realized that android does not update the screen for every instruction in the code, apparently it does so only when a function ends. That being said, I had to do my search in a separate thread in order for the loading to appear between the time the searched started and before it ended.

SherlockFragmentActivity EditText getText() nullpointerexception

I have this error nullpointerexception, when i do getText().toString() from EditTex:
public class SendMessActivity extends SherlockFragmentActivity {
private EditText tEmail;
private Button sendButton;
#Override
protected void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.send_mess_layout);
tEmail = (EditText)findViewById(R.id.editEmailTo);
sendButton = (Button)findViewById(R.id.btn_sendmess);
endButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
//String textEmail = tEmail.getText().toString(); //nullpointerexception
Editable textEmail1Editable = tEmail.getText(); //nullpointerexception
String textEmail = textEmail1Editable.toString()
Log.d(DEBUGTAG, "SENDING START:::::::: " + textEmail);
}
});
}}
Please, tell me how to do it
UPDATE Q
David, thank you, for your surmise,the problem was really in the my tangled Layouts
I had all 4 levels of nesting LinearLayouts.
After I left the simplified scheme and only 2 levels I have, all began to work
You need to call setContentView(your_layout.xml) so it knows what layout to use. Without setting the layout, all of your calls to findViewById(...) that try to find the views in your layout will return null.
public class SendMessActivity extends SherlockFragmentActivity {
private EditText tEmail;
private Button sendButton;
#Override
protected void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(your_layout.xml); //set your activity layout here.
tEmail = (EditText)findViewById(R.id.editEmailTo);
sendButton = (Button)findViewById(R.id.btn_sendmess);
endButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
String textEmail = tEmail.getText().toString(); //nullpointerexception
Log.d(DEBUGTAG, "SENDING START:::::::: " + textEmail);
}
});
}}
If you have no assigned text then I would assume that the EditText retrieval of the text would be a null entry and you are attempting to make a string of that null entry.

EditText to int using Integer.parseInt

I'm new to programming and Android. I'm making my best attempt at a simple app and I'm stuck!
I have two editTexts (set to accept numbers only) and a button. The idea is to display the sum of the two user inputs when the button is pressed. However, my app stops working and force closes when I click the button in the emulator.
Any help would be greatly appreciated.
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_prevailing_torque);
Button calculatePrevailing = (Button) findViewById(R.id.button_calculatePrevailing);
calculatePrevailing.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
TextView prevailingSetting = (TextView) findViewById(R.id.textViewSetting);
EditText editTextPrevailing = (EditText) findViewById(R.id.editTextPrevailing);
EditText editTextRecommended = (EditText) findViewById(R.id.editTextReccomended);
int p = Integer.parseInt(editTextPrevailing.getText().toString());
int r = Integer.parseInt(editTextRecommended.getText().toString());
prevailingSetting.setText(r+p);
}
});
}
I've looked at several similar questions on here but I haven't been able to find anything that I can implement further than what I have already done. But I am probably looking in the wrong places.
Thanks!
You can't use setText() with an Integer since it expects a CharSequence, you have to use
prevailingSetting.setText(String.valueOf(r+p));
or just
prevailingSetting.setText(""+(r+p));
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_prevailing_torque);
Button calculatePrevailing = (Button) findViewById(R.id.button_calculatePrevailing);
TextView prevailingSetting = (TextView) findViewById(R.id.textViewSetting);
EditText editTextPrevailing = (EditText) findViewById(R.id.editTextPrevailing);
EditText editTextRecommended =(EditText)findViewById(R.id.editTextReccomended);
calculatePrevailing.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
int p = Integer.parseInt(editTextPrevailing.getText().toString());
int r = Integer.parseInt(editTextRecommended.getText().toString());
int s = r+p;
prevailingSetting.setText(Integer.toString(s));
}
});
Ok ! if this is your problem then first of all convert your editText value to string and after that convert it into integer like !
String str1=editTextPrevailing.getText().toString();
String str2=editTextRecommended.getText().toString();
int p = Integer.parseInt(str1);
int r = Integer.parseInt(str2);
int s = r+p;
prevailingSetting.setText(""+s);

Trouble converting an editable to a string (username/password test)

I'm trying to create a simple username/password login screen. I have the layout done, and right now, I'm trying to set it so when the username (EditText) == "crete", then it should do something. Here is my code...:
public class Login extends Activity {
public static EditText username, password;
public Button loginbutton;
boolean accessgranted;
public String dbu, dbp, user1;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.login);
username = (EditText) this.findViewById(R.id.username);
password = (EditText) this.findViewById(R.id.password);
loginbutton = (Button) this.findViewById(R.id.loginbutton);
user1 = "crete";
loginbutton.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
try{
dbu = (username.getText()).toString();
}
finally{
if (dbu == user1){
username.setText("SUCCESS");
}
}
}
});
}
}
this, sadly, doesn't work. It correctly converts it to a string (i think) because when I tested this code out :
loginbutton.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
try{
dbu = (username.getText()).toString();
}
finally{
username.setText("done" + dbu);
}
}
}
});
It correctly enters what you entered into the EditText, plus the word "done".
There seems to be a problem with creating if-then statements??
You test for String equality with the method .equals("String").
With == you are testing if the references to the objects are equal.
Try using equalsIgnoreCase(String) instead of the == comparator.
Like this: dbu.equalsIgnoreCase(user1)
dub and user1 are two separate String objects. You're comparing them like this: dbu == user1. This will always return false. Instead, replace it with dbu.equals(user1).

Categories

Resources