1

Please Help,

whay the result if(Title.toString().trim() == "camera") is false?
my code:

mGridView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
                //Get item at position
                GridMenuItem item = (GridMenuItem) parent.getItemAtPosition(position);
                String Title =item.getTitle();
                if(Title.toString().trim() == "camera"){

                    String strPhoneNumber;
                    Bundle b = getIntent().getExtras();
                    strPhoneNumber = b.getString("phonenumber");

                    Intent myIntent = new Intent(v.getContext(), UploadActivity.class);
                    Bundle bs = new Bundle();
                    bs.putString("phonenumber", strPhoneNumber); //Your id
                    myIntent.putExtras(b); //Put your id to your next Intent
                    startActivityForResult(myIntent, 0);
                    finish();
                }
                if(Title.toString() =="history"){
                    Intent myIntent = new Intent(v.getContext(), HistoryActivity.class);
                    startActivityForResult(myIntent, 0);
                }
                if(Title.toString() =="setting"){
                    Intent myIntent = new Intent(v.getContext(), HistoryActivity.class);
                    startActivityForResult(myIntent, 0);
                }

            }
        });

debug

3

3 Answers 3

1

Change the code like this:

mGridView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
                //Get item at position
                GridMenuItem item = (GridMenuItem) parent.getItemAtPosition(position);
                String Title =item.getTitle().toString().trim();
                Log.d("testString",Title);
                if(Title.equals("camera")){

                    String strPhoneNumber;
                    Bundle b = getIntent().getExtras();
                    strPhoneNumber = b.getString("phonenumber");

                    Intent myIntent = new Intent(v.getContext(), UploadActivity.class);
                    Bundle bs = new Bundle();
                    bs.putString("phonenumber", strPhoneNumber); //Your id
                    myIntent.putExtras(b); //Put your id to your next Intent
                    startActivityForResult(myIntent, 0);
                    finish();
                }
                if(Title.equals("history")){
                    Intent myIntent = new Intent(v.getContext(), HistoryActivity.class);
                    startActivityForResult(myIntent, 0);
                }
                if(Title.equals("setting")){
                    Intent myIntent = new Intent(v.getContext(), HistoryActivity.class);
                    startActivityForResult(myIntent, 0);
                }

            }
        });

Please post the value of log "testString" in the comment below. Look if it shows "Camera" instead of "camera" then change the if statement accordingly.

Sign up to request clarification or add additional context in comments.

Comments

0

Try this

Title.equals ("camera")

Since title is a string there is no need for using toString and trim

Comments

0

if(Title.toString().equal("camera"))

Because in java, String is an Object Type(Reference) so you must use equal instead of ==.

"==" operator is using for primitive types only (like int, long ...)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.