如何从Android中动态创建的EditText获取值?如何从Android中动态创建的编辑文本中获取价值?
这是我的动态视图(XML文件)
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<EditText
android:id="@+id/et_waypoint"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@drawable/background"
android:hint="Way Points"
android:padding="10dp"
android:textSize="16sp" />
<Button
android:id="@+id/btn_waypoint"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Find" />
</LinearLayout>
,我使用LayoutInflater
因为我想完美设计布局,是不是我通过setLayoutParams
完成,所以这是我使用LayoutInflater
的原因。
这里是我的代码:
LayoutInflater l = getLayoutInflater();
final LinearLayout mainActivity = (LinearLayout) findViewById(R.id.dynamic);
final View view = l.inflate(R.layout.dynamic_layout_waypoints, null);
buttonWayPoints = (Button) view.findViewById(R.id.btn_waypoint);
editTextWayPoints = (EditText) view.findViewById(R.id.et_waypoint);
mainActivity.addView(editTextWayPoints);
我是新来的Android。大多数人建议this solution但它不适合我,问题是当我执行此代码我的添加新编辑文本按钮没有回应我。
这是我想获得插入值,但它只返回最后创建编辑文本的价值:
public Cursor getPerson(String Query) {
SQLiteDatabase db = this.getReadableDatabase();
Cursor c = db.rawQuery(Query, null);
return c;
}
某人是StringBuilder sb;
,w是String w;
String quaryWayPoints = "select * from route_table where trip_id = " + t;
Cursor s = myDb.getPerson(quaryWayPoints);
int count3 = s.getCount();
for (int j = 0; j < count3; j++) {
s.moveToNext();
w = s.getString(s.getColumnIndex("waypoints"));
// se.append(w + "." + "00");
}
trip_name.setText(n);
trip_date.setText(d);
sb.append(w);
}
trip_route.setText(sb.toString());
你能在这里发布错误日志 –
'editTextWayPoints.getText()。toString()'应该从你的EditText中得到你的文本。 –
请注意,增加喊叫或投票建议往往会吸引downvotes,如果两者兼而有之,则会加倍。请不要添加到您的帖子。 – halfer