I do not know the number. of textview which should be created at runtime. List of Textviews are getting from server. I am creating textviews using below function. Since i am new to android i unable to get text from all textviews. Please suggest me the solution
private void textview(String text)
{
TextView txt_view= new TextView(this);
txt_view.setText(text);
linearLayout.addView(txt_view);
}
Please suggest me the solution i m stuck in getting the text from many textview
Above image is my form, what i want to get text from all views which are created dynamically and store to firebase
add your TextView to HashMap with a unique key
and match your key and get value from map, it will surely help you. after that at time of fetching data use for loop and get data using that unique key
Just get it from your TextView object, like this:
txt_view.getText().toString();
Use same object of TextView to gt text of it. txt_view.getText().toString();
You can get same TextView object by finding childs of LinearLayout.
How about to store them in an ArrayList and iterate over it to get all and maniupulate them afterwards.
ArrayList<TextView> alTextViews = new ArrayList<>();
private void textview(String text) {
TextView txt_view= new TextView(this);
alTextView.add(txt_view);
txt_view.setText(text);
linearLayout.addView(txt_view);
}
with
alTextView.get(0).getText().toString();
you'll get the text
Related
I have an arraylist containing 100 words. I want to assign each word to an individual textview of RecyclerView, but all the textviews of my Recyclerview show the same data, i.e the last word.
for(String s:arraylist){
viewholder.textview.setText(s);
}
Above is my Adapter Code for RecyclerView. How should I resolve this?
Try this:
viewholder.textview.setText(arraylist.get(position));
Instead of
for(String s:arraylist){
viewholder.textview.setText(s);
}
Use following below code for Set the values in textview from the ArrayList in `RecyclerView.
viewholder.textview.setText(arrayList.get(position));
I hope this may help you,
I develop android application that in my application all layouts and widgets are created dynamically.
All data will be received from a JSON file and all ids for elements are also in the same file.
for example I want use this
String id=txt_site_id
TextView txt = new TextView(this);
txt.setID(id);
but it's can't work because setid just use int value for create dynamic id
Now,How I can Resolve my Problems
thanks
First thing came into my mind was using a Tag:
txt.setTag(id);
(...)
txt.getTag(id);
If this isn't enough, please provide more input, what you try to achieve.
I have the code below in my adapter that creates dynamically EditTexts and set IDs using the method "et_settingValue.setId(setting.getId());".
An Editbox is created in every instace of the class Setting and it also contains a variable to store its id.
This part is already working properly, but now I need to access all those created EditTexts by ID and get its data. If possible, I would like to avoid creating another array to store the EditTexts because I already have their IDs.
Is there any way to do it using the dynamic IDs I already have?
EditText et_settingValue = (EditText) view.findViewById(R.id.et_settingValue);
et_settingValue.setText(setting.getValue().trim());
et_settingValue.setId(setting.getId());
Update 1
In my activity, I am trying to do this:
EditText et = new EditText(listView.getContext());
//loop to get each object child
settingConfig.getConfigName(); //ok
settingConfig.getConfigValue(); //ok
settingConfig.getConfigId(); //ok
et = (EditText) listView.findViewById(settingConfig.getConfigId()); //not working
et.getText(); // off course it will not working
Many thanks
ListView use a RecycleBin to reuse the view created from Adapter, so ListView will only contain a few child view, and you cannot find all EditText in the ListView.
To solve your problem, you should use a Map to record the value of all EditText. Add TextWatcher to each of them, and refresh the value in the Map on text changed.
My team and I are making an android chat application. We want to display the messages sent by the users in a ListView. How can we display the text entered in an EditText in the list view. Or is there any other way to achieve our goal?
It all depends on what type of adapter you're using to back the view. If you're using an ArrayAdapter, just add the text to the array each time you have a new message you want to display (for instance, every time a button was clicked). If you're using a CursorAdapter, you'd then have to add the text to the ContentProvider that the Cursor is viewing. Beyond that, I can't tell you much else. We'd need more details about what you're doing in order to answer any further.
I've done this with some different by your needs. I just get the editText values to my database and printed into EditText. Just see this code -
EditText b = (EditText)findViewById(R.id.editText1);
b.setVisibility(1);
output = (TextView) this.findViewById(R.id.editText1);
output1 = (TextView) this.findViewById(R.id.editText2);
String s1= output1.getText().toString();
this.dh = new DataHelper(this);
this.dh.insert(s1);
List<String> names = this.dh.selectAll();
StringBuilder sb = new StringBuilder();
sb.append("Names in database:\n\n");
for (String name : names)
{
sb.append("\t - \t" + (name) + "\n");
}
this.output.setText(sb.toString());
Just change this with your needs. Try out using this
You can do this using the custom list view. In the custom list view use the custom adapter in which you can take an edit TextView. You can see this how to implement custom list view here. In this list view a TextView is used but you can replace this TextView with EditText view.
I am new in android programming.
I am creating a app where I supposed to use multiple textviews. Number of TextViews go on changing according to number of records fetched from database.
Here, i was trying to number textviews as textView1, textView2, textView3,...
but as i am unaware about the number of records, i can not define them statically
is there any way to do so dynamically
like we do in PHP
e.g
$count = 1;
if(condition)
{
textView.$count;
$count++;
}
Thanx in advance.
You should create a List of TextViews and populate it dynamically
List<TextView> list = new LinkedList<TextView>();
Find the total number of record at runtime and create the TextView in a loop for each textView and finally ad it to the current layout.
For example:
for(int i=0;i<data.size;i++){
TextView tv=new TextView(this);
tv.setText(data.get(i));
currentLayput.addView(tv);
}
where data is some vector or Arraylist in which you can store the data from database.