My main.xml has 2 edit text for the user to insert values. And my custom_list_item.xml has a text view and an edit text. The input of the user would be inserted into the text view and edit text respectively.
However, currently I am only able to pass 1 value into the adapter. How can I pass the other value over to the adapter?
main.java
public class main extends Activity{
ArrayList<String> noteList = new ArrayList<String>();
FancyAdapter aa = null;
Button calculate;
EditText result;
String total;
String name;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
final Spinner spinner = (Spinner)findViewById(R.id.spinner);
ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(
this, R.array.spinner_array, android.R.layout.simple_spinner_item);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinner.setAdapter(adapter);
ListView myListView = (ListView)findViewById(R.id.noteList);
aa = new FancyAdapter();
final EditText price = (EditText)findViewById(R.id.price);
final EditText name1 = (EditText)findViewById(R.id.name);
final EditText result = (EditText)findViewById(R.id.result);
myListView.setAdapter(aa);
myListView.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> arg0, View arg1,
int position, long arg3) {
aa.notifyDataSetChanged();
}
});
Button btnSimple = (Button)findViewById(R.id.btnSimple);
btnSimple.setOnClickListener(new OnClickListener() {
public void onClick(View v)
{
double totalPrice = Double.parseDouble(price.getText().toString());
int position = spinner.getSelectedItemPosition();
name = name1.getText().toString();
if(position == 0)
{
totalPrice = totalPrice * 1.07;
total = String.valueOf(totalPrice);
System.out.println(total);
//result.setText(total);
}
else
{
totalPrice = (totalPrice * 1.1)*1.07;
total = String.valueOf(totalPrice);
System.out.println(total);
//result.setText(total);
}
noteList.add(0, total);
System.out.println(total);
name1.setText("");
price.setText("");
aa.notifyDataSetChanged();
}
});
}
class FancyAdapter extends ArrayAdapter<String>
{
Button calculate;
EditText price;
EditText result;
FancyAdapter()
{
super(main.this, android.R.layout.simple_list_item_1, noteList);
}
public View getView(int position, View convertView, ViewGroup parent)
{
View row = convertView;
if(row == null)
{
LayoutInflater inflater = getLayoutInflater();
row = inflater.inflate(R.layout.custom_list_item, null);
}
//((TextView)row.findViewById(R.id.nametv)).setText(noteList.get(position));
((EditText)row.findViewById(R.id.result)).setText(noteList.get(position));
return (row);
}
}
}
You can just send a whole string to the adapter. Then split the string up accordingly. You may want to add a colon or some identifier to split.