vendredi 15 mai 2015

How to know the View Elements after loading a layout?

I am trying to write code , where after loading the Layout , i want to know which are the view elements are related to the layout like TextView, EditText , Checkbox etc.

MyCode :

MainActivity.java

package com.example.myview;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentTransaction;
import android.support.v7.app.ActionBarActivity;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;


public class MainActivity extends ActionBarActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);


    View view = LayoutInflater.from(this).inflate(R.layout.demo_layout, null);
    // How to get to know about the UI Elements related to this layout //

    }


}

demo_layout.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 
    xmlns:android="http://ift.tt/nIICcg"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

 <LinearLayout 
           android:id="@+id/lnr"    
           android:layout_width="match_parent"
           android:layout_height="match_parent"
           android:background="#ddccee"
           android:orientation="vertical">

        <TextView 
            android:id="@+id/txt1"
            android:layout_width="match_parent"
            android:layout_height="300dp"
            android:textSize="15dp"
            android:textColor="#ffffff"
            android:text="Test Layout"
            android:layout_gravity="center"
            android:gravity="center"/>

        <EditText 
            android:id="@+id/edit1"
            android:layout_width="match_parent"
            android:layout_height="300dp"
            android:textSize="15dp"
            android:textColor="#ffffff"
            android:text="Test Layout"
            android:layout_gravity="center"
            android:gravity="center"/>


        <TextView 
            android:id="@+id/txt2"
            android:layout_width="match_parent"
            android:layout_height="300dp"
            android:textSize="15dp"
            android:textColor="#ffffff"
            android:text="Test Layout"
            android:layout_gravity="center"
            android:gravity="center"/>


</LinearLayout>

This layout has TextView , EditText , so , i want to know how to get UI elements are related to this layout programmatically.

So , please suggest me some solution.

Aucun commentaire:

Enregistrer un commentaire