2015-11-11 39 views
0

我有活動A和B. 活動A有textViewbutton。 活動B有一個textView和一個editTextTextView不能意圖到另一個類,即使它不是null

我想實現的是讓活動A中的c可點擊,如果它不爲空。

當它在活動A中時,它顯示null。當我單擊button來表示B並將resultname返回給A時,如果單擊c,它應該顯示not null並且可以intentEditClaims.java

但現在的問題是它沒有顯示not null當從B處返回resultname A和不intentEditClaims.javac是點擊。

因此,這是該活動的流程應該怎麼看起來像

活動A >>顯示空>>按鈕點擊>>進入B >>從b返回resultname到A >>顯示NOT NULL >>如果點擊c,則轉到EditClaims.java

 String result=""; 
       String name="" 
       public View onCreateView(LayoutInflater inflater, ViewGroup container, 
              Bundle savedInstanceState) { 
         super.onCreate(savedInstanceState); 
         Bundle bundle = this.getArguments(); 
        View claims = inflater.inflate(R.layout.claims, container, false); 
        c = (TextView) claims.findViewById(R.id.textView49); 
        Button button1 = (Button) claims.findViewById(R.id.button10); 

        button1.setOnClickListener(new View.OnClickListener() { 
       @Override 
       public void onClick(View v) { 
        // Toast.makeText(getActivity().getApplicationContext(), fk + "", Toast.LENGTH_LONG).show(); 
        AlertDialogRadio(a1); 


       } 
      }); 

    public void AlertDialogRadio(final int k) { 
      final CharSequence[] ClaimsModel = {"B", "C", "D"}; 

      AlertDialog.Builder alt_bld = new AlertDialog.Builder(getActivity()); 
      alt_bld.setTitle("Select a Claims"); 
      alt_bld.setSingleChoiceItems(ClaimsModel, -1, new DialogInterface 
        .OnClickListener() { 

       public void onClick(DialogInterface dialog, int item) { 
        if (item == 0) { 
         Intent intent = new Intent(getActivity().getApplicationContext(), B.class); 
         startActivityForResult(intent, 0); 
        } else if (item == 1) {...} 
            ..... 

        }); 

      } 
       if ((name != null && name.trim().length() > 0) && (result != null && result.trim().length() > 0)) { // check whether c is null or not null 
          Toast.makeText(getActivity().getApplicationContext(), "not null", Toast.LENGTH_LONG).show(); 
          c.setOnClickListener(new View.OnClickListener() { 
           @Override 
           public void onClick(View v) { 
            Intent intent = new Intent(getActivity(), EditClaims.class); 
            startActivity(intent); 
           } 
          }); 
         }else 
         { 
          Toast.makeText(getActivity().getApplicationContext(), "null", Toast.LENGTH_LONG).show(); 
         } 




          } 
         }); 
       return claims; 
        } 

     @Override 
      public void onActivityResult(int requestCode, int resultCode, Intent data) 
    int button = data.getIntExtra("k1", 0); 
{ 

       if (button == 1) { 
        switch (requestCode) { 
         case 0: 
          result = data.getStringExtra("text"); // return from B 
          name = data.getStringExtra("a"); //return from B 
          as=Long.parseLong(result); 
          c.setText("   " + name + "------" + "RM " + result); 
          break; 

活動B

public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.B); 
     txt = (EditText) findViewById(R.id.editText36); 
     txt1=(TextView)findViewById(R.id.textView57); 
     Button b = (Button) findViewById(R.id.button17); 
     addListenerOnButton(); 


     b.setOnClickListener(new View.OnClickListener() { // save button 
      public void onClick(View arg0) { 
       Intent returnIntent = new Intent(); 
       a = "Project"; 
       text = txt.getText().toString(); 
       returnIntent.putExtra("text", text); 
       returnIntent.putExtra("a", a); 
       setResult(Activity.RESULT_OK, returnIntent); 
       finish(); 
      } 
     }); 

    } 
+0

你能讀取onActivityResult()中的值嗎?什麼是按鈕== 1? – sr09

+0

@ sr09雅,它可以.'結果'和'名稱'可以顯示在c。 – Tony

+0

@ sr09我只是在Activity A中展示了一部分代碼。但是我想要實現的是讓c'clickable'如果它不爲null – Tony

回答

0
c.setOnClickListener(new View.OnClickListener() { 
           @Override 
           public void onClick(View v) { 
            if ((name != null && name.trim().length() > 0) && (result != null && result.trim().length() > 0)) { 
             Toast.makeText(getActivity().getApplicationContext(), "not null", Toast.LENGTH_LONG).show(); 

               Intent intent = new Intent(getActivity(), EditClaims.class); 
               startActivity(intent); 


             } 
            else { 
             Toast.makeText(getActivity().getApplicationContext(), "null", Toast.LENGTH_LONG).show(); 
            } 
           } 
            }); 

這將是作品每次TextView的點擊。

相關問題