Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SharedPreference giving me unknown LOG

I want to know what the log that shows means when the Buttom Navigation Bar is clicked, The text information inside this item is stored in the prefrence.

this is the code for navigation item when clicked :

case R.id.navigation_gift:
    View view = View.inflate(getApplicationContext(), R.layout.section_fragment_69, null);
    TextView txtEmtiaz = (TextView) view.findViewById(R.id.txtEmtiaz);
    SharedPreferences sp = getSharedPreferences("entire", 0);
    txtEmtiaz.setText(sp.getString("tik", ""));
    Log.e("POPI", "txt in main2 :" + String.valueOf(txtEmtiaz));

This is the Log information that is displayed:

/POPI: txt in main2 :android.widget.TextView{1e42d479 V.ED.... ......ID 0,0-0,0 #7f09016d app:id/txtEmtiaz}
like image 373
Diyako Avatar asked Sep 03 '18 07:09

Diyako


1 Answers

You need to get text from txtEmtiaz and then set it to sp shared preference.

Problem is at below line:

txtEmtiaz.setText();

Change to:

sp.putString("tik", txtEmtiaz.getText());

Problem in log:

  Log.e("POPI", "txt in main2 :" + String.valueOf(txtEmtiaz));

You are trying to print txtEmtiaz i.e. txtEmtiaz object which of course you can not.

You should use like below to print value (text) of txtEmtiaz TextView:

  Log.e("POPI", "txt in main2 :" + txtEmtiaz.getText());
like image 54
Vikasdeep Singh Avatar answered Sep 27 '22 23:09

Vikasdeep Singh