findviewbyid

How to do a findViewById (R.id.>> StringVarHere << )?

限于喜欢 提交于 2019-12-12 10:43:21
问题 Searched and working on this a long while - no luck. ( It must be simple ? Thanks for the assist. ) Trying to get / set a screen full of EditTexts' text, but not with the usual, more hard-coded way: ... findViewById (R.id.SomeTextWidgetId) ; Instead, I'm trying to figure out a reusable way via a variable holding the (String) name_of_widget. In psuedo code: findViewById (R.id.>> StringVarHere << ); // how to do that ? I tried also this findViewById method, but it didn't work (!?) //// given:

android findviewbyid() use int at id field

孤人 提交于 2019-12-12 01:59:39
问题 I have a pretty simple question: int i=0; n = (TextView) findViewById(R.id. "value of i" ); How can I get this working? I want in the place of id to use my int value, is it possible? if so how do I go about doing this? I'll put the code: private void sxhmatismos7(String[][] pinakas) { TextView n; int i=0; for (i=0;i<12;i++) { n = (TextView) findViewById(R.id."HERE VALUE OF i"); if (n.getText().equals(pinakas[0][0])) { n.setVisibility(View.VISIBLE); } } } 回答1: Something like this should work:

Android Eclipse findViewByID with programmatically CheckBox

微笑、不失礼 提交于 2019-12-12 01:07:08
问题 I create a few CheckBoxes programatically like this: public int cb_id = 1000; public void create_cb() { CheckBox cb1 = new CheckBox(this); cb1.setText("My CheckBox"); cb1.setId(cb_id); LinearLayout ll_checkbox = (LinearLayout) findViewById(R.id.ll_checkbox); ll_checkbox.addView(cb1); } This work's fine for me, but I can't find the CheckBox with the ID... public void find_cb() { CheckBox cb1 = (CheckBox) findViewById(cb_id); String content = cb1.getText().toString(); } This is not working, the

“findViewById” with for loop [duplicate]

百般思念 提交于 2019-12-11 20:34:37
问题 This question already has answers here : Accessing contents of R.string using a variable to represent the resource name (4 answers) Android: Using findViewById() with a string / in a loop (7 answers) Closed 4 years ago . it's my code: ImageView img1 = (ImageView) findViewById(R.id.img1); ImageView img2 = (ImageView) findViewById(R.id.img2); ImageView img3 = (ImageView) findViewById(R.id.img3); ImageView img4 = (ImageView) findViewById(R.id.img4); ImageView img5 = (ImageView) findViewById(R.id

findViewById Error cant find id in XML

雨燕双飞 提交于 2019-12-11 19:27:41
问题 I cant find out why my findViewById is not linking to the XML file and it is driving me nuts. The is is in the XML file but it is still not Finding it in the java MainActivity file. here is my XML <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal

Reference to EditText in ViewPager creates null pointer exception

那年仲夏 提交于 2019-12-11 14:06:25
问题 What I'm trying to do: Have users input data on 3 different fragments, then on the 4th fragment the user will review all data input into the first 3 fragments before submitting to a database. The issue I'm having: Every method I've tried to set or get from the EditText's creates a NullPointerException My question: For what I'm trying to do, what is the correct method to call for the text value of an EditText from one fragment, and set that text in an EditText in another fragment anytime a

Reference to findViewById() is ambiguous when running unit test

无人久伴 提交于 2019-12-10 22:15:18
问题 this morning I updated Android Studio to the latest stable 3.x build, together with support libraries, buildTools version and the new gradle plugin I managed to get everything work (with a lot of pain dure to the new gradle plugin), but now I have a problem which I can't really understand: The project compiles, and the unit tests of PROJECT1 and PROJECT2 run fine, but when I try to run unit tests of main project, I get this error: Error:(40, 30) error: reference to findViewById is ambiguous

Android ViewHolder简洁写法及替代findViewById方法

邮差的信 提交于 2019-12-10 16:58:33
ViewHolder简洁写法,避免适配器中重复定义ViewHolder: import android.util.SparseArray; import android.view.View; @SuppressWarnings({"unchecked"}) public class ViewFindUtils { /** * ViewHolder简洁写法,避免适配器中重复定义ViewHolder,减少代码量用法: * <p/> * <pre> * if (convertView == null) * { * convertView = View.inflate(context, R.layout.ad_demo, null); * } * TextView tv_demo = ViewHolderUtils.get(convertView, R.id.tv_demo); * ImageView iv_demo = ViewHolderUtils.get(convertView, R.id.iv_demo); * </pre> */ public static <T extends View> T hold(View view, int id) { SparseArray<View> viewHolder = (SparseArray<View>) view.getTag(); if

Android O Preview findViewById compile error

一世执手 提交于 2019-12-08 16:31:55
问题 I tried to test the Android O Developer Preview second phase. After the project was created, I just clicked build and run but I didn't have any success. Android default generated code below: Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); compile error occurred. Error:(18, 37) error: reference to findViewById is ambiguous both method findViewById(int) in Activity and method <T>findViewById(int) in AppCompatActivity match where T is a type-variable: T extends View declared in method <T

SetText of TextView in DialogFragment from Calling Activity

人走茶凉 提交于 2019-12-08 09:56:48
问题 Building an Android app and having some trouble. I'd appreciate any help! I have created an class that extends DialogFragment (Account_Create_Error) that I call from Activity A. I want to set the TextView field in this DialogFragment from Activity A. I created a method in my dialogfragment public void setError(String message) { TextView error = (TextView)getActivity().findViewById(R.id.message); error.setText(message); } I then use this method in Activity A by doing Account_Create_Error error