Android Problem calling TextView from second layout file

后端 未结 4 581
情书的邮戳
情书的邮戳 2021-01-24 08:34

Hey guys the main layout xml file for my activity is R.layout.date_list_layout as it is used as follows

 public void onCreate(Bundle savedInstanceState) {
 super         


        
相关标签:
4条回答
  • 2021-01-24 09:09

    As Second TextView is the part of another layout so we have to used

     setContentView(R.layout.R.layout.display_item);
    

    So for second TextView Change you code to

    setContentView(R.layout.display_item);
    
    TextView currency = (TextView) findViewById(R.layout.display_item/R.id.currency);
    
    currency.setText(cur);
    
    0 讨论(0)
  • 2021-01-24 09:17

    What you are doing should not be done unless you are embedding the layout in the current layout (layout 1) and in that case you need to use include layout.

    In case you want to access data and set it from one activity to another. Use SharedPreference to store the text in this activity and when the other activity launches which used the second layout as its content view, you can use this SP to access the data and set the text view.

    0 讨论(0)
  • 2021-01-24 09:33

    I think you can solve yuor problems with Intent data. You're starting your activity via Intent, right? If so, just pass desired data (cur...) via Intent and that's it.

    0 讨论(0)
  • 2021-01-24 09:34

    You first need ot inflate the other xml layout file in order to be able to do stuff on the TextView.

    (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE).inflate(R.layout.display_item);
    
    0 讨论(0)
提交回复
热议问题