2012-01-19 17 views
1

私のmain.xmlには、値を挿入するための2つの編集テキストがあります。私のcustom_list_item.xmlには、テキストビューと編集テキストがあります。ユーザの入力は、テキストビューに挿入され、テキストをそれぞれ編集する。Android - 複数の値をアダプタに渡す

しかし、現在のところ、アダプタには1つの値しか渡すことができません。他の値をアダプタに渡すにはどうすればよいですか?

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); 
    } 
} 

}

答えて

0

ための複数の基準です以下、BaseAdapterクラスを拡張してカスタムアダプタを作成します。ちょうど全体を送るアダプタに文字列を送ります。それに応じて文字列を分割します。コロンまたは分割するための識別子を追加することができます。

0

することができます同じ

adapter tutorial

Same question here

+0

可能であれば、元のコードを追加コード – Hend

+0

で貼り付けてコードに固執したい、または問題を解決したいと考えています。 BaseAdapterクラスの使用をお勧めします。より多くの機能を提供します。一度これを行うと、Listにいくつかの経験があります.ListViewで複数のビューを表示する場合は、BaseAdapterクラスを使用して独自のアダプタを作成することをおすすめします。 – AAnkit

関連する問題