开发者

How to get particular view id if two layout have same view id?

I have two layouts in same project which content TextView having same id. I want to access text view id of particular layout. how to get it?

EX.

how to access TextView of Layout1.xml ?

layout1 XML File:

   <RelativeLayout 
    android:id="@+id/TopPanel"
    android:layout_width="fill_parent" 
    android:background="@drawable/header" 
    android:layout_height="45dip"
    android:gravity="top"
    android:orientation="horizontal">

    <TextView 
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" 
        android:layout_alignParentLeft="true"
        android:layout_centerVertical="true"
        android:paddingLeft="4dip"
        android:id="@+id/title1" 
        android:background="@color/transparent"
        android:textColor="@color/white" 
        android:textAppearance="?android:attr/textAppearanceLarge"
        android:singleLine="true" 
        android:text="@string/AllMessages" 
        android:textStyle="bold"/>
</RelativeLayout>

layout2 XML File:

    <FrameLayout 
    android:id="@+id/flayout"
    android:layout_width="fill_parent" 
    android:background="@drawable/header" 
    android:layout_height="45dip"
    android:gravity="top"
    android:orientation="horizontal">

    <TextView 
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" 
        android:layout_alignParentLeft="true"
        android:layout_centerVertical="true"
        android:paddingLeft="4dip"
        android:id="@+id/title1" 
        android:background="@color/transparent"
        android:textColor="@color/white" 
        android:textAppearance="?android:attr/textAppearanceLarge"
        android:singleLine="true" 
        a开发者_开发知识库ndroid:text="@string/AllMessages" 
        android:textStyle="bold"/>
     </FrameLayout>

Code:

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
    setContentView(R.layout.layout1);
  View vw =findViewById(R.layout.layout1);
  TextView tvBannerText =(TextView) vw.findViewById(R.id.title1);
      tvBannerText.setTextColor(bannerTextColor);
      tvBannerText.invalidate();


then you can do this..

TextView t1 = layout1.findViewById(R.id.yourTextView);

Layout l2 = layout1.findViewById(R.Layout.layout2);

TextView t1 = l2.findViewById(R.id.yourTextView);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜