Click here to Skip to main content
15,889,834 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi i have custom dialog box that load another layout to itself but i can't access textviews in that layou.
Java
View checkBoxView = View.inflate(this, R.layout.money_list, null);
      final MaterialDialog mMaterialDialog = new MaterialDialog(this).setView(checkBoxView);

      mMaterialDialog.setTitle("MaterialDialog");
      mMaterialDialog.setPositiveButton("خب", new View.OnClickListener() {
          @Override
          public void onClick(View v) {
              mMaterialDialog.dismiss();

          }
      });


      mMaterialDialog.show();

layout.money_list:
XML
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="match_parent" android:layout_height="match_parent"
    android:id="@+id/LinerLayoutMoneyList"
    >

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:layout_marginTop="10dp"
        >

        <ImageView
            android:layout_width="50dp"
            android:layout_height="50dp"
            android:id="@+id/imgDollar"
            android:background="#FF33FF"
            android:layout_alignParentTop="true"
            android:layout_alignParentRight="true"
            android:layout_alignParentEnd="true"
            android:layout_marginRight="10dp"
            android:layout_marginEnd="10dp" />

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textAppearance="?android:attr/textAppearanceLarge"
            android:text="دلار"
            android:layout_centerVertical="true"
            android:layout_toLeftOf="@+id/imgDollar"
            android:layout_toStartOf="@+id/imgDollar"
            android:layout_marginRight="17dp"
            android:layout_marginEnd="17dp"
            android:id="@+id/textView9" />   
 </RelativeLayout>
</LinearLayout>

i use this code to access to the textview but it not work without any error:
Java
LayoutInflater inflater = getLayoutInflater();
View myView = inflater.inflate(R.layout.money_list, null);
TextView myTextView = (TextView) myView.findViewById(R.id.tvDerham);

myTextView.setText("3468430248");
Posted
Comments
TorstenH. 28-Apr-15 8:09am    
Theres a RelativLayout in a LinearLayout.. Why is that? Is that the reason?
Behnam Mohammadi 28-Apr-15 8:42am    
yes the relatives stand for items i have items that implemented with relative
JoCodes 28-Apr-15 9:37am    
Cant see any where you have inflated LinerLayoutMoneyList id of the layout
Behnam Mohammadi 28-Apr-15 11:25am    
u mean is, i use
View myView = inflater.inflate(R.id.LinerLayoutMoneyList, null);
but it not work it has error
JoCodes 28-Apr-15 12:30pm    
whats the error?

1 solution

Please check your textview id once.
In Xml you are using
android:id="@+id/textView9"
and in code you are using R.id.tvDerham
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900