我无法使用从活动传递到片段的捆绑字符串数据在textView中设置文本

Briingz:

数据从ProjectDetailActivity传递到ProjectDetailFragment,我已经检查了数据是否可以通过使用Toast显示数据来传递到片段,如在代码中看到的那样,但是问题是我无法通过使用bundle中的数据在Textview中设置文本。如果您在此代码中看到一些错误,请告诉我。非常感谢。

ProjectDetailActivity类

         private String project_key,project_name,project_priority,project_category,
                        project_start_date ,project_end_date,project_description;
         @Override
         protected void onCreate(Bundle savedInstanceState) {
              super.onCreate(savedInstanceState);
              setContentView(R.layout.activity_project_detail);

              Intent intent = getIntent();
              project_key         = intent.getStringExtra("project_key");
              project_name        = intent.getStringExtra("project_name");
              project_category    = intent.getStringExtra("project_category");
              project_priority    = intent.getStringExtra("project_priority");

              Bundle bundle = new Bundle();
              bundle.putString("project_key",project_key);
              bundle.putString("project_name",project_name);
              bundle.putString("project_category",project_category);
              bundle.putString("project_priority",project_priority);

              ProjectDetailFragment project_detail_fragment =new ProjectDetailFragment();
              project_detail_fragment.setArguments(bundle);
              getSupportFragmentManager().beginTransaction()
                .replace(R.id.project_detail_fragment,project_detail_fragment)
                .commit();

          }
     }

ProjectDetailFragment类

 public class ProjectDetailFragment extends Fragment {
      private View root;

      private String project_key,project_name,project_priority,project_category,


      private TextView project_name_textView , project_priority_textView ,
                       project_category_textView ;

      private Context mContext;

      public ProjectDetailFragment() { }

      @Override
      public void onCreate(@Nullable Bundle savedInstanceState) {
           super.onCreate(savedInstanceState);
           if (getArguments() != null) {
                Bundle bundle = getArguments();
                project_key           = bundle.getString("project_key");
                project_name          = bundle.getString("project_name");
                project_priority      = bundle.getString("project_category");
                project_category      = bundle.getString("project_priority");
           }
      }

      public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle 
                  savedInstanceState) {
            root =  inflater.inflate(R.layout.fragment_project_detail, container,false);

            project_name_textView        = root.findViewById(R.id.project_name_textView);
            project_priority_textView    = root.findViewById(R.id.priority_textView);
            project_category_textView    = root.findViewById(R.id.category_textView);


            project_name_textView.setText(project_name);
            project_priority_textView.setText(project_priority);
            project_category_textView.setText(project_category);

            Toast.makeText(mContext,"TASK ACTIVITY\n"+
                    project_key+"\n"+project_name+"\n"+project_category+"\n"
                    +project_priority+"\n",Toast.LENGTH_SHORT).show();

            return root;
       }

       @Override
       public void onAttach(Context context) {
            super.onAttach(context);
            mContext=context;
       }
 }
Mubashir Murtaza:

如果Toast向您显示数据,则意味着接收数据没有问题,并且在将数据设置为文本视图时我看不到任何错误,但是请检查您的xml,如果文本颜色与背景颜色匹配则检查文本颜色,例如文本视图的背景为白色,文本颜色也为白色,显然比看不到文本。或者如果没有的话,您可以这样尝试::::: project_name_textView.setText((。project_name)的String.value);

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

我无法将活动的数据(字符串)发送到活动中包含的片段

将字符串从活动传递到片段

将字符串变量从活动传递到片段

如何将字符串从片段传递到活动

将字符串和整数从活动传递到片段

我无法在Android应用程序的TextView中设置字符串(使用Java)

Android-使用Button从片段1到片段2在EditText中传递字符串

使用选项卡式活动中的捆绑将值从活动传递到片段

如何将字符串从活动传递到 android 中选项卡式活动的片段

将数据片段传递到同一活动中的片段

无法从活动传递意图字符串

无法将空字符串传递到非空数据库字段中

如何在另一个活动传递的字符串中添加文本,并在Textview中显示结果文本

在Android中将数据从活动传递到片段无法正常工作

将字符串从活动B传递到活动A

如何将编辑文本字符串从一个活动传递到另一个活动中的方法?

android-将数据从活动传递到ViewPager中的片段

无法将字符串值从一个片段传递到另一个片段

使用安全Args将数据从活动传递到片段

使用ListView将数据从片段传递到活动

使用接口将数据从活动传递到片段

如何使用TabLayout将数据从活动传递到片段

将字符串变量从recyclerview传递到片段

将字符串传递给自定义类时,无法在UICollectionViewCell中设置标签文本

无法在NLog中设置我的连接字符串

如何在同一活动中将字符串从textview传递到另一个texview?

如何将字符串数据从服务传递到我的活动

将文本从textview插入到字符串中,然后在字符串目标c中返回NSMallocBlock

在viewpager中的片段之间传递字符串无法正常工作