- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我的应用程序(API 11)根据用户输入创建 EditTexts 并为每个 Id 提供。当用户填写每个编辑文本时,我需要执行空检查,获取数据并将其发送到下一个 Activity 。但现在我被困住了,因为我无法引用它们。我该怎么办?
谢谢
XML:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context="com.wima.civilengineeringcalculator.twodtruss"
tools:showIn="@layout/activity_twodtruss"
android:orientation="vertical"
android:background="#4A148C"
android:layoutDirection="ltr">
<ScrollView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fillViewport="true"
android:layout_alignParentTop="true"
android:id="@+id/scr1">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="تحلیل خرپاهای دو بعدی:"
android:textColor="#FFFFFF"
android:id="@+id/textView1"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"/>
<View
android:layout_height="2dip"
android:layout_width="wrap_content"
android:layout_below="@+id/textView1"
android:background="#4A148C"
android:id="@+id/V3"/>
<View
android:layout_height="2dip"
android:layout_width="wrap_content"
android:layout_below="@+id/V3"
android:background="#4A148C"
android:id="@+id/V5"/>
<View
android:layout_height="2dip"
android:layout_width="wrap_content"
android:layout_below="@+id/V5"
android:background="#FF909090"
android:id="@+id/V4"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="تعداد اعضا:"
android:textColor="#FFFFFF"
android:id="@+id/textView4"
android:layout_below="@+id/V4"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"/>
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toLeftOf="@+id/textView4"
android:layout_toStartOf="@+id/textView4"
android:textColor="#FFFFFF"
android:ems="10"
android:id="@+id/editT"
android:layout_below="@+id/V4"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:inputType="number" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="تعداد گره های سازه:"
android:id="@+id/textView5"
android:textColor="#FFFFFF"
android:layout_below="@+id/editT"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"/>
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="number"
android:ems="10"
android:textColor="#FFFFFF"
android:id="@+id/editT2"
android:layout_below="@+id/editT"
android:layout_toLeftOf="@+id/textView5"
android:layout_toStartOf="@+id/textView5"
android:layout_alignLeft="@+id/editT"
android:layout_alignStart="@+id/editT"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="تعداد مقاطع مورد نیاز:"
android:textColor="#FFFFFF"
android:id="@+id/textView6"
android:layout_below="@+id/editT2"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"/>
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:id="@+id/editT3"
android:textColor="#FFFFFF"
android:layout_below="@+id/editT2"
android:layout_alignLeft="@+id/editT"
android:layout_toLeftOf="@+id/textView6"
android:layout_alignStart="@+id/editT"
android:layout_toStartOf="@+id/textView6"
android:inputType="number" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="مرحله بعد"
android:textColor="#000000"
android:background="@drawable/btn_selector"
android:id="@+id/button5"
android:layout_below="@+id/editT3"
android:layout_alignLeft="@+id/editT3"
android:layout_alignRight="@+id/editT3"
android:layout_alignStart="@+id/editT3"
android:layout_alignEnd="@+id/editT3"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="راهنما"
android:textColor="#000000"
android:background="@drawable/btn_selector"
android:id="@+id/button6"
android:layout_below="@+id/editT3"
android:layout_alignLeft="@+id/textView5"
android:layout_alignRight="@+id/textView4"
android:layout_alignStart="@+id/textView5"
android:layout_alignEnd="@+id/textView4"/>
<View
android:layout_height="2dip"
android:layout_width="wrap_content"
android:layout_below="@+id/button5"
android:background="#4A148C"
android:id="@+id/V1"/>
<View
android:layout_height="2dip"
android:layout_width="wrap_content"
android:layout_below="@+id/V1"
android:background="#FF909090"
android:id="@+id/V2"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="مشخصات مقاطع را وارد نمایید:"
android:textColor="#FFFFFF"
android:id="@+id/textView7"
android:layout_below="@+id/V1"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"/>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/sectable"
android:layout_below="@+id/textView7">
</TableLayout>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="مرحله بعد"
android:textColor="#000000"
android:background="@drawable/btn_selector"
android:id="@+id/button1"
android:layout_below="@+id/sectable"
android:layout_alignLeft="@+id/button6"
android:layout_alignRight="@+id/button6"
android:layout_alignStart="@+id/button6"
android:layout_alignEnd="@+id/button6"
android:onClick="next1" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="شروع مجدد"
android:textColor="#000000"
android:background="@drawable/btn_selector"
android:id="@+id/button2"
android:layout_below="@+id/sectable"
android:layout_alignLeft="@+id/editT3"
android:layout_alignRight="@+id/editT3"
android:layout_alignStart="@+id/editT3"
android:layout_alignEnd="@+id/editT3"/>
</RelativeLayout>
</ScrollView>
Java 代码:
public class MatrixAnalysis extends AppCompatActivity {
private TableLayout mLayout;
private EditText noofsecs;
private EditText Noele;
private EditText Nonode;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_twodtruss);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
Noele = (EditText) findViewById(R.id.editT);
Nonode = (EditText) findViewById(R.id.editT2);
noofsecs = (EditText) findViewById(R.id.editT3);
title = (TextView) findViewById(R.id.textView1);
Button bt_calculate1 = (Button) findViewById(R.id.button5);
Button bt_help = (Button) findViewById(R.id.button6);
Button bt_N1 = (Button) findViewById(R.id.button1);
Button bt_reset = (Button) findViewById(R.id.button2);
TextView inter = (TextView) findViewById(R.id.textView7);
bt_help.setVisibility(View.INVISIBLE);
bt_N1.setVisibility(View.INVISIBLE);
bt_reset.setVisibility(View.INVISIBLE);
inter.setVisibility(View.INVISIBLE);
bt_calculate1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if ( Noele.getText().toString().trim().equals("")
|| Nonode.getText().toString().trim().equals("")
|| noofsecs.getText().toString().trim().equals("")) {
Snackbar.make(findViewById(android.R.id.content), "لطفا مقادیر تمامی متغیرها را وارد کنید ", Snackbar.LENGTH_LONG)
.show();
}
else {
double noofsecs1 = Double.valueOf(noofsecs.getText().toString());
for (nsecctr = 1; nsecctr < noofsecs1 + 1; nsecctr++) {
mLayout = (TableLayout) findViewById(R.id.sectable);
prepuserinput();
}
}
}
});
Double Dnoofsecs = 5.0;
int aRows = Dnoofsecs.intValue();
double [] Asec = new double[aRows];
double [] Esec = new double[aRows];
double [] Gsec = new double[aRows];
double [] Iysec = new double[aRows];
double [] Izsec = new double[aRows];
double [] Jsec = new double[aRows];
public void prepuserinput() {
Button bt_calculate1 = (Button) findViewById(R.id.button5);
Button bt_help = (Button) findViewById(R.id.button6);
Button bt_N1 = (Button) findViewById(R.id.button1);
Button bt_reset = (Button) findViewById(R.id.button2);
TextView inter = (TextView) findViewById(R.id.textView7);
Noele = (EditText) findViewById(R.id.editT);
Nonode = (EditText) findViewById(R.id.editT2);
noofsecs = (EditText) findViewById(R.id.editT3);
bt_calculate1.setVisibility(View.INVISIBLE);
bt_help.setVisibility(View.VISIBLE);
bt_N1.setVisibility(View.VISIBLE);
bt_reset.setVisibility(View.VISIBLE);
inter.setVisibility(View.VISIBLE);
Noele.setEnabled(false);
Nonode.setEnabled(false);
noofsecs.setEnabled(false);
Intent i = getIntent();
String pro = i.getStringExtra("Problem");
double pro1 = Double.parseDouble(pro.replace(",", "."));
int width = getApplicationContext().getResources().getDisplayMetrics().widthPixels;
int width1 = width * 13 / 100;
int width2 = width * 12 / 100;
TableRow tr = new TableRow(this);
tr.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.MATCH_PARENT,
TableRow.LayoutParams.MATCH_PAREN));
TextView textview = new TextView(this);
textview.setId(nsecctr + 0);
textview.setText(":" + nsecctr + "مقطع");
textview.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.MATCH_PARENT,
TableRow.LayoutParams.MATCH_PARENT));
textview.setTextColor(Color.parseColor("#FFFFFF"));
tr.addView(textview);
EditText A = new EditText(this);
A.setId(nsecctr + 0);
A.setHint("A");
A.setLayoutParams(new TableRow.LayoutParams(width2, 50));
A.setInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_DECIMAL);
A.setTextColor(Color.parseColor("#FFFFFF"));
A.setHintTextColor(Color.parseColor("#bdbdbd"));
//width, height
tr.addView(A);
EditText E = new EditText(this);
E.setId(nsecctr + 0);
E.setHint("E");
E.setLayoutParams(new TableRow.LayoutParams(width2, 50));
E.setInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_DECIMAL);
E.setTextColor(Color.parseColor("#FFFFFF"));
E.setHintTextColor(Color.parseColor("#bdbdbd"));
tr.addView(E);
EditText G = new EditText(this);
G.setId(nsecctr + 0);
G.setHint("G");
G.setLayoutParams(new TableRow.LayoutParams(width2, 50));
G.setInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_DECIMAL);
G.setTextColor(Color.parseColor("#FFFFFF"));
G.setHintTextColor(Color.parseColor("#bdbdbd"));
tr.addView(G);
EditText Iy = new EditText(this);
Iy.setId(nsecctr + 0);
Iy.setHint("Iy");
Iy.setLayoutParams(new TableRow.LayoutParams(width1, 50));
Iy.setInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_DECIMAL);
Iy.setTextColor(Color.parseColor("#FFFFFF"));
Iy.setHintTextColor(Color.parseColor("#bdbdbd"));
tr.addView(Iy);
EditText Iz = new EditText(this);
Iz.setId(nsecctr + 0);
Iz.setHint("Iz");
Iz.setLayoutParams(new TableRow.LayoutParams(width1, 50));
Iz.setInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_DECIMAL);
Iz.setTextColor(Color.parseColor("#FFFFFF"));
Iz.setHintTextColor(Color.parseColor("#bdbdbd"));
tr.addView(Iz);
EditText J = new EditText(this);
J.setId(nsecctr + 0);
J.setHint("J");
J.setLayoutParams(new TableRow.LayoutParams(width2, 50));
J.setInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_DECIMAL);
J.setTextColor(Color.parseColor("#FFFFFF"));
J.setHintTextColor(Color.parseColor("#bdbdbd"));
tr.addView(J);
mLayout.addView(tr, new TableLayout.LayoutParams(TableLayout.LayoutParams.MATCH_PARENT,
TableLayout.LayoutParams.MATCH_PARENT));
}
public void next1 (View view) {
double noofsecs1 = Double.valueOf(noofsecs.getText().toString());
Jnew = (EditText) findViewById(R.id.editT3);
for (nsecctr = 1; nsecctr < noofsecs1 + 1; nsecctr++) {
mLayout = (TableLayout) findViewById(R.id.sectable);
Asec[nsecctr] = A.getId();
Esec[nsecctr] = E.getId();
Gsec[nsecctr] = G.getId();
Iysec[nsecctr] = Iy.getId();
Izsec[nsecctr] = Iz.getId();
Jsec[nsecctr] = J.getId();
}
}
最佳答案
你应该创建一个 HashMap
来存储你所有的 EditText
HashMap <String, EditText > mapEditText = new HashMap<String, EditText >();
每当您以编程方式创建 EditText
时,请记住将其放入 HashMap
EditText A = new EditText(this);
...
mapEditText.put("A",A);
EditText E = new EditText(this);
...
mapEditText.put("E",E);
....
在next
方法中,您可以通过
EditText
public void next1 (View view) {
...
Asec[nsecctr] = mapEditText.get("A").getId();
Esec[nsecctr] = mapEditText.get("E").getId();
}
关于java - 如何获取在另一种方法中定义的编辑文本的值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38346053/
我想了解 Ruby 方法 methods() 是如何工作的。 我尝试使用“ruby 方法”在 Google 上搜索,但这不是我需要的。 我也看过 ruby-doc.org,但我没有找到这种方法。
Test 方法 对指定的字符串执行一个正则表达式搜索,并返回一个 Boolean 值指示是否找到匹配的模式。 object.Test(string) 参数 object 必选项。总是一个
Replace 方法 替换在正则表达式查找中找到的文本。 object.Replace(string1, string2) 参数 object 必选项。总是一个 RegExp 对象的名称。
Raise 方法 生成运行时错误 object.Raise(number, source, description, helpfile, helpcontext) 参数 object 应为
Execute 方法 对指定的字符串执行正则表达式搜索。 object.Execute(string) 参数 object 必选项。总是一个 RegExp 对象的名称。 string
Clear 方法 清除 Err 对象的所有属性设置。 object.Clear object 应为 Err 对象的名称。 说明 在错误处理后,使用 Clear 显式地清除 Err 对象。此
CopyFile 方法 将一个或多个文件从某位置复制到另一位置。 object.CopyFile source, destination[, overwrite] 参数 object 必选
Copy 方法 将指定的文件或文件夹从某位置复制到另一位置。 object.Copy destination[, overwrite] 参数 object 必选项。应为 File 或 F
Close 方法 关闭打开的 TextStream 文件。 object.Close object 应为 TextStream 对象的名称。 说明 下面例子举例说明如何使用 Close 方
BuildPath 方法 向现有路径后添加名称。 object.BuildPath(path, name) 参数 object 必选项。应为 FileSystemObject 对象的名称
GetFolder 方法 返回与指定的路径中某文件夹相应的 Folder 对象。 object.GetFolder(folderspec) 参数 object 必选项。应为 FileSy
GetFileName 方法 返回指定路径(不是指定驱动器路径部分)的最后一个文件或文件夹。 object.GetFileName(pathspec) 参数 object 必选项。应为
GetFile 方法 返回与指定路径中某文件相应的 File 对象。 object.GetFile(filespec) 参数 object 必选项。应为 FileSystemObject
GetExtensionName 方法 返回字符串,该字符串包含路径最后一个组成部分的扩展名。 object.GetExtensionName(path) 参数 object 必选项。应
GetDriveName 方法 返回包含指定路径中驱动器名的字符串。 object.GetDriveName(path) 参数 object 必选项。应为 FileSystemObjec
GetDrive 方法 返回与指定的路径中驱动器相对应的 Drive 对象。 object.GetDrive drivespec 参数 object 必选项。应为 FileSystemO
GetBaseName 方法 返回字符串,其中包含文件的基本名 (不带扩展名), 或者提供的路径说明中的文件夹。 object.GetBaseName(path) 参数 object 必
GetAbsolutePathName 方法 从提供的指定路径中返回完整且含义明确的路径。 object.GetAbsolutePathName(pathspec) 参数 object
FolderExists 方法 如果指定的文件夹存在,则返回 True;否则返回 False。 object.FolderExists(folderspec) 参数 object 必选项
FileExists 方法 如果指定的文件存在返回 True;否则返回 False。 object.FileExists(filespec) 参数 object 必选项。应为 FileS
我是一名优秀的程序员,十分优秀!