Android Edittext listviews? - android

I have been scouring the Internet for a way to use an input box at the top of the page, and have an add & remove button.
I want the EditText to write to the ListView, which in turn writes the list to a .txt-file.
I have tried breaking this down into multiple small sections of just simple things like
getting the input from the EditText to post to a TextView.
Organizing a ListView
writing to a file and
reading from a file.
If you have any advice about how to get the ListView to go from the EditText greatly helpful.

The best way to do this is to have an ArrayList<String> to store your Strings from the TextView, and in turn have that ArrayList<String> feed into the ListView. For example, for your Add button handler:
// Declare our variables
ArrayList<String> myStringList = new ArrayList<String>();
// OnClickListener stuff for Add button
..
myStringList.add(myEditText.getText().toString());
myListView.setListAdapter(new ArrayAdapter<String>(getBaseContext(), android.R.layout.simple_list_item_1, myStringList));
..
// Close OnClickListener stuff
Make sure you refresh your list adapter afterwards to show the new values. Likewise if you're deleting, use myStringList.remove(index) to remove that string from the list and refresh the array adapter. As for writing to a text file, have a look at this thread.

Related

Optimization of AutoCompleteTextView initialization

I'm a newcomer to Android world.
I'm facing an performance problem in my app under development.
I've one activity with one AutoCompleteTextView. I'm initializing it on onCreate() of activity with an adapter like below:
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,android.R.layout.simple_dropdown_item_1line, keywords);
final AutoCompleteTextView textView = (AutoCompleteTextView) findViewById(R.id.autoCompleteTextView);
textView.setAdapter(adapter);
The "keywords" is an String[] which I'm reading from json file containing a almost 3000 entries every time on onCreate(). At the same time, I get values against "keyword" and adding to a HashMap
Because of this, loading time of this activity is slowing down.
By what means I can reduce:
Reading json file only one time
Initialize adapter one time
So next time onward I can load the activity faster [First time I can show some "loading..." dialog]
You can try the following
Parse json in a background thread and put a loading bar.
Once strings are parsed and displayed, you save them via in an instance(onSavedInstanceState). As long as activity is not destroyed displaying them will be faster.
Save strings in sharedpreferences or SQlite DB(this option depends on app, like what strings are you displaying).

Android: Storing and showing strings in ListView

I need to have a DialogFragment or similar with a ListView which contains a list of strings. I also need to have some kind of footer or something so I can add more strings to the ListView.
Basically it is a dialog where a user can specify and add endpoints to the app, and clicking on a String of the ListView would make the app connect to that endpoint.
How could I do this? Should I use a ListView with a footer? How could I store the strings in the device?
Thanks a lot in advance!
If you want to store Strings after close your app, you should use SQLite database, there you've got a nice example of use it
SQLite tutorial,
and there you could read how create a DialogFragment with ListView
DialogFragment with ListView.
To put data from database to ListView you should get List<String> someData from your database.
To add new String you could add it to database and refresh all Dialog View, or add it to list using comand someData.add(String string);
Hope I help

List of Strings in multiple buttons

I have a list of Strings (Video tags) and I wanna show each of them in a button (same as when you want to send a text for multiple users) and when I click on each an action happens for that box. I took a look at:
https://github.com/kpbird/chips-edittext-library
It generate each string in a box but finally I don't have access to specific item onclick.
Does anyone has any suggestion what to use or how to make it?!
Read out the array of strings and
programmatically add a button with the text of each
string to for example a LinearLayout.
pseudo code:
ArrayList<string> list = getResources.array("id");
LinearLayout l = (Linearlayout) findViewById(R.id.linearlayout);
foreach(String s in list)
{
l.addView(new Button(s));
}
Something like that.

Listview Row incrementing with new value

I have a listview with radio buttons now i need to add one value from a edittext after typing some thing in the edittext the typed text should appear in the listview as next row.? how it is posible.?
ListView with simpleArrayAdapter :
Follow these steps it may help:
1. Fetch the value from edit text after the user types using gettext()
2. Insert this value in an array.
3. create a list view.
4. create an arrayAdapter with the already created array as source.
5. Now set the adapter with listview using (array variable).setAdapter(adapter name);
For every time the user updates use notifyDataSetChanged() to refresh your listview with the new contents.
Pseudo code:
onClick(){
array.add(editText.gettext());
adapter.notifyDataSetChanged();
}
Click here for more.

auto search in listview

I created a list view which extends ListActivity and I have a search field at the top of the page
but I don't know how to write it , I want a search like search contact (type just only 1 char and listview will change, don't have to press any button)
please give me some example code
thanks
I think you should see this
If you are currently using a CursorAdapter to display the List, than you can create a custom CursorAdapter which does filtering automatically as you type keys. The following webpage provides an excellent example of this: http://thinkandroid.wordpress.com/2010/01/11/custom-cursoradapters/
Good luck!
Create a AutoCompleteTextView in your Layout,then put this in your class file,
AutoCompleteTextView txtPhoneNo = (AutoCompleteTextView) findViewById(R.id.txtPhoneNo);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,android.R.layout.simple_dropdown_item_1line, name_Val);
txtPhoneNo.setAdapter(adapter);
where name_Val is the String Array that contains "DATA"

Categories

Resources