Add getChildAt() to custom tablerow class - android

I've made a TableRow class and added my own methods to it. In the TableRow is a EditText where i want to retreive values from. I thought about using the getChildAt() for finding the right EditText in the right TableRow. But because i made my own TableRow class i can't use the getChildAt() wich is in the original TableRow class or parents of it.
So how can i get the EditText values from the tablerows? Create my own getChildAt method?(if so, how?) or is there a different way?

Example-
EditText editEmail, editPass;
String name = "", pass = "";
editEmail=(EditText)findViewById(R.id.editEmail);
editPass=(EditText)findViewById(R.id.editPass);
name = editEmail.getText().toString();
pass = editPass.getText().toString();
you can try this. the values now in string variable and you can use these variables wherever you want.

Whenever you create dynamic view you can assign an id to that view as
final int ID=1001;
EditText et=new EditText(this);
et.setId(ID);
and get the view using
findviewbyid(ID) ;
If you are using xml
android:id="#+id/ed1"
In Activity
EditText et=(EditText)findViewById(R.id.ed1);

Related

Get value from textview in ListView Android

I'm following this guide to create a listview with textviews and eddittexts in it.
http://www.webplusandroid.com/creating-listview-with-edittext-and-textwatcher-in-android/
When I try to get values from listview items, I get only textviews values. It seems impossible getting text from the edittext based on listview position.
I use lv.getItemAtPosition(0).toString()) to retrieve values
Following: Android: Access child views from a ListView
int wantedChild = 1;
View wantedView = listview.getChildAt(wantedChild);
mEditText = (EditText) wantedView.findViewById(R.id.edittext);
Log.d("result",(mEditText.getText().toString()));

User option of an element

How can i set my own option on view?
I need something like this:
TableRow tblr_data = new TableRow(this);
tblr_data.setOption("my_option", "my_option_value"); //there is no such method
Another words i need to add custom option to table row (custom id for example) and then use it in onclick handler.
If I understand your question correctly, you could use the setTag(int key, Object tag) method.
//member variable
private int MY_OPTION = 1;
//when creating your tablerow
tblr_data.setTag(MY_OPTION, "my_option_value");
then in your onClickListener, you can just fetch that value again by calling
String value = (String)tblr_data.getTag(MY_OPTION);
See this accepted answer for more on the get/setTag() method.
What is the main purpose of setTag() getTag() methods of View?

How to display multiple number of TextViews inside each row in ListView programatically?

as I am new in Android, facing an issue with my App. I have to show multiple no. of TextViews inside each row of ListView as Each row can have different no. of TextViews. Please Help me to create TextView inside row Programatically and display text inside every row according to dataCount.
Say....i have to create a row( LinearLayout, that is vertically oriented) having multiple no. of String values from ArrayList and need to create a single textview that can display data for ArrayList but my problem is that each row of listview have different no. of ArrayList count and ArrayList values. how can i solve it?
Thanks
Instat of Linear layout You can use table layout.
TableRow newRow;
TableLayout tbl;
int length=10; //As your wish;
EditText[] ex = new EditText[length];
for(t=0;t<length;t++){
newRow = (TableRow) new TableRow(this);
newRow.setClickable(true);
ex[t]=(EditText) new EditText(this);
newRow.addView(ex[t]);
newRow.setId(t);
tbl.addView(newRow);
}
Try this way,hope this will help you to solve your problem.
HashMap<Integer, ArrayList<String>> list = new HashMap<Integer, ArrayList<String>>();
Set hashmap key as index and value of string array list now pass to list adapter on adapter "getView()" method get position wise hashmap data and get their value,iterate value ArrayList as size make as no of TextView add on list item row layout.

how can I access editText value in class which extends listactivity in android

I want to access values entered using editText in class which extends ListActivity.
I am not able to use findviewbyid method to access editText. Which method should I use? Can somebody help me
I think your EditText is in custom view of your list item if yes then try something like this :
View oView = LayoutInflater..inflate(R.layout.your_custom_layout, null);
EditText yourEditText = (EditText)oView.findViewById(R.id.your_edit_text_id_from_xml_file);
String editTextValue = yourEditText.getText().toString();

Android: give textfield 'id' in java

I was wondering how to give a TextField an 'id' in java. So I am pretty much wanting to know how to give the TextField android:id="#id/NAMEHERE" but do it in java. Here is the code so far:
TextView taskname = new TextView(this);
taskname.setText("Task " + tasknumber);
tasklayout.addView(taskname);
What do I need to add to give it an id?
If your question is to how to set id into activity, then understand purpose of id.
Id is specially required when you want to fetch view reference into activity class, where view has been declared into xml file. But in Activity, if you are creating any view, by
TextView taskname = new TextView(this);
here, you already have view reference, but if you still want to set id, then you can use method
taskname.setId(10002);
Try this
static final int TEXT_ID = 80001;
TextView taskname = new TextView(this);
taskname.setId(TEXT_ID);
and later in your code you can refer to this textview by
TextView t = (TextView)findViewById(TEXT_ID);
or
TextView t = taskname;

Categories

Resources