![](/img/trans.png)
[英]If I bind an object of one of my classes to a scripting engine, how can I access it as an object of that class from withing the scripting engine?
[英]How can I access an EditText withing my custom ListView
这可能是一个简单的答案,但我在这方面花了太长时间,所以我真的可以使用一些帮助。
我只是想获取存储在我的 EditText 中的值。 将发布一些代码。
发票创建器.java
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_invoice_creator);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
toolbar.inflateMenu(R.menu.menu_invoice_creator);
myDb = new DatabaseHelper(this);
EditText ItemCost;
Bundle NameIntentData1 = getIntent().getExtras();
if (NameIntentData1==null){
return;
}
String IntentDataID1 = NameIntentData1.getString("Client ID1");
String IntentDataName1 = NameIntentData1.getString("Client Name");
String IntentDataAddress1 = NameIntentData1.getString("Client Address");
final TextView IDBar1 = (TextView) findViewById(R.id.InvoiceCreatorIDTV);
final EditText Namebar1 = (EditText) findViewById(R.id.InvoiceCreatorNameET);
final EditText AddressBar1 = (EditText) findViewById(R.id.InvoiceCreatorAddressET);
IDBar1.setText(IntentDataID1);
//IDBar1.setText(IntentDataName1);
//AddressBar1.setText(IntentDataAddress1);
Spinner spinMonths1 = (Spinner) findViewById(R.id.InvoiceCreatorMonthSpinner);
ArrayAdapter<CharSequence> months = ArrayAdapter.createFromResource(this, R.array.Months, android.R.layout.simple_spinner_dropdown_item);
months.setDropDownViewResource(android.R.layout.simple_list_item_1);
spinMonths1.setAdapter(months);
Spinner spinYear1 = (Spinner) findViewById(R.id.InvoiceCreatorYearSpinner);
ArrayAdapter<CharSequence> years = ArrayAdapter.createFromResource(this, R.array.Years, android.R.layout.simple_spinner_dropdown_item);
years.setDropDownViewResource(android.R.layout.simple_list_item_1);
spinYear1.setAdapter(years);
String[] foods = {"Service: Bag \'n\' Cut", "Service: Mulch Thrown", "Service: Grass Seed",
"Service: Spring Decoration", "Service: Snow Plow" };
//S:Bag//S.Mul//S.Gra//S.Spr//S.Snw
String[] costs = {"150", "150", "150", "150", "150"};
ListAdapter adapterservices = new custom_ServiceAdapter(this, foods);
ListView servicelist = (ListView) findViewById(R.id.InvoiceCreatorMonthHistoryListView);
servicelist.setAdapter(adapterservices);
还有我的custom_row_layout
<TextView
android:id="@+id/customName"
android:layout_width="210dp"
android:layout_height="wrap_content"
android:background="@android:color/darker_gray"
android:clickable="false"
android:text="TextView"
android:textAlignment="center"
android:textColor="@android:color/black"
android:textSize="24sp"
android:textStyle="bold" />
<EditText
android:id="@+id/Cost"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/CheckService"
android:layout_alignParentEnd="true"
android:layout_weight="1"
android:editable="false"
android:ems="10"
android:hint="Cost"
android:inputType="none"
android:textSize="24sp" />
<CheckBox
android:id="@+id/CheckService"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_alignParentTop="true"
android:layout_toEndOf="@+id/customName"
android:checked="false"
android:clickable="false"
/>
<TextView
android:id="@+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_toStartOf="@+id/Cost"
android:text="$"
android:textColor="@android:color/background_dark"
android:textSize="40sp" />
我只是想提取EditText
成本的价值。
我怀疑这与膨胀视图有关。
任何帮助是极大的赞赏。
您应该创建扩展 ArrayAdapter 的自定义适配器。 看看这个。
在您将 EditText 绑定到列表视图的适配器中,您可以使用 EditText.getText().toString();
或者您可以使用自定义界面来处理用户输入的输入
因此,据我了解您的问题,您有一份食物清单,您需要从ListView
每一行中的EditText
获取食物成本。
现在,如果您想将EditText
数据保留在ListView
那么我建议您对数据结构进行细微更改。
您正在获取一组字符串,它是食物,另一个数组是成本。 我想建议您制作一个包含两者的对象并填充ListView
的对象数组。 所以你的对象可能看起来像这样。
public class Food {
public String name;
public String cost;
}
现在得到ArrayList
你的食物和填充ArrayList
,只要你想。
public ArrayList<Food> generateFoods() {
ArrayList<Food> foodList = new ArrayList<Food>();
String[] foods = {"Service: Bag \'n\' Cut", "Service: Mulch Thrown", "Service: Grass Seed", "Service: Spring Decoration", "Service: Snow Plow" };
String[] costs = {"150", "150", "150", "150", "150"};
for (int i = 0; i < foods.length; i++) {
Food food = new Food();
food.name = foods[i];
food.cost = costs[i];
foodList.add(food);
}
return foodList;
}
现在将ArrayList
传递给您的适配器并填充ListView
的项目。 有关如何从ArrayList
填充ListView
教程,请参阅 。
我想给出另一个使用RecyclerView
而不是ListView
建议。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.