EditText Array List - android

Is there a way to store EditText into a list array. For example,
n1I1 = (EditText) findViewById(R.id.etN1I1);
n1I2 = (EditText) findViewById(R.id.etN1I2);
n1I3 = (EditText) findViewById(R.id.etN1I3);
n2I1 = (EditText) findViewById(R.id.etN2I1);
n2I2 = (EditText) findViewById(R.id.etN2I2);
n2I3 = (EditText) findViewById(R.id.etN2I3);
into
FirstList[]={n1I1,n1I2,n1I3}
SecondList[]={n2I1,n2I2,n2I3}.
I would like to have it like this so that it is easy for me to keep track of number input by user. While at it, how can I store double(eg. 31.12) value into an arraylist?
Thanks.

You have 2 options:
//Array
EditText[] FirstList = {n1I1,n1I2,n1I3};
//or ArrayList
List<EditText> FirstList = new ArrayList<EditText>(){{
add(n1I1);
add(n1I2);
add(n1I3);
}};

use an ArrayList object, not a regular array:
ArrayList<EditText> firstList = new ArrayList<EditText>();
firstList.add(n1I1);
firstList.add(n1I2);
firstList.add(n1I3);
ArrayList<EditText> secondList = new ArrayList<EditText>();
secondList.add(n2I1);
secondList.add(n2I2);
secondList.add(n2I3);

Related

get value from Dynamically add multiple spinner in android?

How to get value to dynamically add multiple spinner where spinner id is same.i used 'String spin = parent.getSelectedItem().toString();' but i get all time last spinner value.Plz help me?
you can create array list of spinner
ArrayList<Spinner> listSpinner = new ArrayList<>();
listSpinner.add(spinner1);
listSpinner.add(spinner2);
listSpinner.add(spinner3);
for(int i=0;i<listSpinner.size();i++){
String p1 = listSpinner.get(i).getSelectedItem();
}
get different value for all spinner out side for loop and store it in arraylist.
ArrayList<Spinner> listSpinner = new ArrayList<>();
ArrayList<ArrayList<String>> s‌​tatus_list = new ArrayList<>();
status_data.add("" + snapshot.getValue());// getting data
s‌​tatus_list.add(status_data);
for (int i = 0; i < 10; i++) {
View v = LayoutInflater.from(AssetCodingDetails.this).inflate(R.layou‌​t.custom_asset_codin‌​g_label, null);
Spinner spinner_status = (Spinner) v.findViewById(R.id.spinner_status);
ArrayAdapter adapter = new ArrayAdapter(getApplicationContext(), R.layout.spinner_item, s‌​tatus_list.get(i));
spinner_status.setAdapter(adapter);
listSpinner.add(spinner_status);
}
for(int i=0;i<listSpinner.size();i++){
String p1 = listSpinner.get(i).getSelectedItem().toString();
}

MPAndroidChart PieChart - set data from plain text input

I'm making an app that I can input name and money and calculate together. Example i input like this in plain text
User 1 = $520
User 2 = $241
User 3 = $253
User 4 = $704
Total = $1718
and here are the id i declared for my plain texts
name1 = (EditText) findViewById(R.id.editName1);
name2 = (EditText) findViewById(R.id.editName2);
name3 = (EditText) findViewById(R.id.editName3);
name4 = (EditText) findViewById(R.id.editName4);
money1 = (EditText) findViewById(R.id.editMoney1);
money2 = (EditText) findViewById(R.id.editMoney2);
money3 = (EditText) findViewById(R.id.editMoney3);
money4 = (EditText) findViewById(R.id.editMoney4);
but how can I set the data from plain text to PieGraph?
Convert the text to numbers (integer, float, ...)
Add them like this:
float number1 = ...; // parse your EditText input here
// other numbers ...
ArrayList<Entry> vals = new ArrayList<Entry>();
vals.add(new Entry(number1, 0));
vals.add(new Entry(number2, 1));
vals.add(new Entry(number3, 2));
vals.add(new Entry(number4, 3));
String[] xVals = new String[] { "User1", "User2", "User3", "User4" };
PieDataSet dataSet = new PieDataSet(vals, "User Values");
PieData data = new PieData(xVals, dataSet);
pieChart.setData(data);
// refresh
pieChart.invalidate();
Also, the example project shows numerous use cases of how data can be added to the charts, you might wanna check it out.
Furthermore, the documentation is pretty good and also gives examples and instructions on how to add data.

Generate number of Edit Text by storing andretrieve each value

I want to generate number of EditText column wise to store and retrieve each value .
Anyone can help me ?
I hope this may help you to resolve your problem.
EditText[] etxt = new EditText[Size];
EditText et;
//Generate and set values
for(int i=0;i<Size;i++)
{
et = new EditText(this);
et.setText(""+i)
et.setId(i);
etxt[i] = et;
//Add item to your view
//YourView.addView(etxt[i]);
}
Now you need to add to your View
//Get values
for(int s=0;s<etxt.lenght;s++)
{
etxt[s] = et;
Log.i("Test","Value: "+etxt[i].getText().toString());
}

get inputs in an edittext dynamically and pass that to next screen

This is my code..I have created a dynamic screen where i am generating one textview and edittext under a for loop.but after button click it is only getting the last input.I need to get all the inputs of editText and have to pass them to new screen..guyss..plzz help me out.here is my code..
runOnUiThread(new Runnable() {
public void run() {
final LinearLayout findViewById = (LinearLayout) findViewById(R.id.dynamicInputs);
// TextView textView = (TextView) findViewById(R.id.name);
TextView textView = new TextView(Activity_UserInput.this);
textView.setText(map.get(KEY_NAME) + " :");
textView.setTextColor(Color.BLACK);
textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 17);
findViewById.addView(textView);
final EditText editText = new EditText(
Activity_UserInput.this);
editText.setText("");
editText.setFocusableInTouchMode(true);
editText.requestFocus();
findViewById.addView(editText);
final ArrayList<EditText> allEds = new ArrayList<EditText>();
allEds.add(editText);
btn.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
// it = new Intent(Activity_UserInput.this,
// Submition_Activity.class);
// it.putExtra("input", arryList);
// System.out.println("get the input"
// + arryList);
String[] string = new String[allEds.size()];
for (int i = 0; i < string.length; i++) {
string[i] = allEds.get(i).getText().toString();
}
}
});
}
});
Here, in your code arraylist of EditText created every time.So initialize allEds at startup
final ArrayList<EditText> allEds = new ArrayList<EditText>();
and then add EditText to arraylist
final EditText editText = new EditText( Activity_UserInput.this);
editText.setText("");
editText.setFocusableInTouchMode(true);
editText.requestFocus();
findViewById.addView(editText);
allEds.add(editText);
You are creating a new allEds everytime you put final ArrayList<EditText> allEds = new ArrayList<EditText>(); So the allEds will contain just one element.
Try creating it outside the for loop.
You have created only one edittext and also you have added only one edittext to the allEds arraylist. You have also declared the size of the string[] to be the size of the allEds arraylist. So, the length of string[] will be 1 only and the for loop will execute only once. so that, you will get only one input.
If you want to create multiple edittext create them inside a for loop. Or if you are already creating them under a for loop try to declare the following line outside the loop instead of declaring inside.
{ArrayList<EditText> allEds = new ArrayList<EditText>();}
My Layout :
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:id="#+id/mTopLayout" ></LinearLayout>
Within my activity
LinearLayout mLayout = (LinearLayout) findViewById(R.id.mTopLayout);
ArrayList<EditText> mCheck = new ArrayList<EditText>();
EditText mEdit = new EditText(MainActivity.this);
mEdit.setText("");
mEdit.setFocusableInTouchMode(true);
mEdit.requestFocus();
mLayout.addView(mEdit);
mCheck.add(mEdit);
EditText mEdit1 = new EditText(MainActivity.this);
mEdit1.setText("");
mEdit1.setFocusableInTouchMode(true);
mEdit1.requestFocus();
mLayout.addView(mEdit1);
mCheck.add(mEdit1);
EditText mEdit2 = new EditText(MainActivity.this);
mEdit2.setText("");
mEdit2.setFocusableInTouchMode(true);
mEdit2.requestFocus();
mLayout.addView(mEdit2);
mCheck.add(mEdit2); ......
Within onClick method
String[] st = new String[mCheck.size()];
for(int i=0;i<st.length;i++){
st[i] = mCheck.get(i).getText().toString();
}
Log.i("Recived String", st.length+"");
for(int j=0;j<st.length;j++){
Log.i(" String", st[j]+""+j); }
It works fine for me....Please review your layout and let me know.... thanks...

How to add a value to arraylist in android?

I am adding a value to my arraylist but it is showing error. Before adding the value I am displaying it first. The value is displaying but it is not adding to the arraylist. Please help me regarding this...
My Code:
static ArrayList<String> allfirstids;
ArrayList<String> list = List.get(i);
UserBO user = new UserBO();
user.firstid = Integer.parseInt(list.get(0));
user.secondid = Integer.parseInt(list.get(1));
System.out.print("Hello this is first id");
System.out.print(list.get(0));
allfirstids.add(list.get(0));
System.out.println("first ids"+allfirstids);
Thanks in advance...
before adding, please initialize arraylist.
allfirstids = new ArrayList<String>();
You forgot to initialize your static ArrayList allfirstids, Just initialize it, before using..
static ArrayList<String> allfirstids = new ArrayList<String>();
ArrayList<String> list = List.get(i);
UserBO user = new UserBO();
user.firstid = Integer.parseInt(list.get(0));
user.secondid = Integer.parseInt(list.get(1));
System.out.print("Hello this is first id");
System.out.print(list.get(0));
allfirstids.add(list.get(0));
System.out.println("first ids"+allfirstids);

Categories

Resources