ユーザーが ListView の TextView に挿入したすべての数値をカウントする方法のコーディングに問題があります...
これが私のアプリです...リストビューの行から合計を取得し、それらを別のテキストビューに表示する方法だけです:
これは私の主な活動です:
public class MainActivity extends Activity {
private Adapter adapter;
private ArrayList<Ruka> fetch = new ArrayList<Ruka>();
Button bt;
EditText et;
TextView tv;
TextView mi;
TextView vi;
ListView lv;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Inflate the menu; this adds items to the action bar if it is present.
bt = (Button) findViewById(R.id.button1);
et = (EditText) findViewById(R.id.editText1);
tv = (TextView) findViewById(R.id.textView1);
mi = (TextView) findViewById(R.id.textViewMi);
vi = (TextView) findViewById(R.id.textViewVi);
lv = (ListView) findViewById(R.id.lista);
// final String input = et.getText().toString();
bt.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
if (et.getText().length() == 0) {
Toast.makeText(this, "test",
Toast.LENGTH_SHORT).show();
return;
}
if (Float.valueOf(et.getText().toString()) >= 12) {
Toast.makeText(this,
"test2", Toast.LENGTH_SHORT)
.show();
return;
}
String input = et.getText().toString();
if (null != input && input.length() > 0) {
String maxpunti = "11";
int a = Integer.parseInt(maxpunti);
int b = Integer.parseInt(input);
int c = a - b;
String input2 = String.valueOf(c);
Ruka one = new Ruka(input, input2);
fetch.add(one);
et.setText("");
adapter = new Adapter(MainActivity.this, R.id.lista, fetch);
lv.setAdapter(adapter);
}
}
});
}
}
これは私のアダプターです:
public class Adapter extends ArrayAdapter<Ruka>{
private ArrayList<Ruka> entries;
private Activity activity;
public Adapter(Activity a, int textViewResourceId, ArrayList<Ruka> entries) {
super(a, textViewResourceId, entries);
this.entries = entries;
this.activity = a;
}
public static class ViewHolder{
public TextView item1;
public TextView item2;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View v = convertView;
ViewHolder holder;
if (v == null) {
LayoutInflater vi =
(LayoutInflater)activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
v = vi.inflate(R.layout.row, null);
holder = new ViewHolder();
holder.item1 = (TextView) v.findViewById(R.id.textView1);
holder.item2 = (TextView) v.findViewById(R.id.textView2);
v.setTag(holder);
}
else
holder=(ViewHolder)v.getTag();
final Ruka custom = entries.get(position);
if (custom != null) {
holder.item1.setText(custom.getFirst());
holder.item2.setText(custom.getSecond());
}
return v;
}
}
アップデート
ここにあるRuka.java
:
public class Ruka {
private String customBig;
private String customSmall;
public Ruka(String string, String string2) {
this.customBig = string;
this.customSmall = string2;
}
public String getFirst() { return customBig; }
public void setcustomBig(String getFirst) { this.customBig = getFirst; }
public String getSecond() { return customSmall; }
public void setcustomSmall(String getSecond) { this.customSmall = getSecond; }
}
誰かが解決策を見つけることができれば...お願い...誰でも:)