Android examples for android.view:View
Obtain the text of the given component by view id
import android.app.Activity; import android.view.View; import android.widget.EditText; import android.widget.TextView; public class Main { /**//w ww . j ava2s . c o m * Obtain the text of the given component. * * @param viewId * The id of the component. * @return The contained text, null otherwise. */ public static String getText(View parent, int viewId) { String text = null; View view = parent.findViewById(viewId); if (view instanceof TextView) text = ((TextView) view).getText().toString(); if (view instanceof EditText) text = ((EditText) view).getText().toString(); return text; } public static String getText(Activity activity, int viewId) { return getText(activity.getWindow().getDecorView().getRootView(), viewId); } }