设想:
用户点击一个顿,并添加一行(火箭)。 用户的投入具有价值,并点击生成的纽扣吨。 该数值将计算并在编辑文本中展示。
问题: 价值没有计算,也没有在编辑文本中显示。 我做了什么错误?
custom_list_item.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:gravity="center">
<EditText
android:id="@+id/name"
android:layout_width="125dp"
android:layout_height="wrap_content"
android:hint="Name"
android:maxLength="10"
/>
<EditText
android:id="@+id/price"
android:layout_width="80dp"
android:layout_height="wrap_content"
android:hint="Price"
android:inputType="numberDecimal"
android:maxLength="5"
/>
<Button
android:id="@+id/calculate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Calculate"
/>
</LinearLayout>
<EditText
android:id="@+id/result"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:editable="false"
android:cursorVisible="false"
android:text="$0.00"
/>
主编:java<<EDITTED>>
public class AdvancedBillSplitter extends Activity{
ArrayList<String> noteList = new ArrayList<String>();
FancyAdapter aa = null;
Button calculate;
//EditText price;
EditText result;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
ListView myListView = (ListView)findViewById(R.id.noteList);
aa = new FancyAdapter();
myListView.setAdapter(aa);
myListView.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> arg0, View arg1,
int position, long arg3) {
EditText price = (EditText)findViewById(R.id.price);
price = (EditText)findViewById(R.id.price);
double price1 = Double.parseDouble(price.getText().toString());
double total = price1 *1.1;
String resultPrice = Double.toString(total);
result.setText(resultPrice);
System.out.println(total);
}
});
aa.notifyDataSetChanged();
Button btnSimple = (Button)findViewById(R.id.btnSimple);
btnSimple.setOnClickListener(new OnClickListener() {
public void onClick(View v)
{
noteList.add(0, "");
aa.notifyDataSetChanged();
}
});
}
class FancyAdapter extends ArrayAdapter<String>
{
Button calculate;
EditText price;
EditText result;
FancyAdapter()
{
super(AdvancedBillSplitter.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);
}
return (row);
}
}
}