【发布时间】:2019-10-30 10:04:15
【问题描述】:
有什么办法可以完成这件事。我正在从另一个活动获取输入以创建动态 editText 以获取输入。
public class GetNames extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.names);
LinearLayout ll = findViewById(R.id.lin);
Bundle bundle = getIntent().getExtras();
String entered_no = bundle.getString("no_of_persons");
for (int i = 0; i < (Integer.valueOf(entered_no)); i++) {
EditText editText = new EditText(GetNames.this);
editText.setId(editText.generateViewId());
ll.addView(editText,0);
editText.setHint(i);
}
}
}
有没有办法解决这个问题。
她是我的 XML 文件
<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">
<LinearLayout
android:layout_width="wrap_content"
android:id="@+id/lin"
android:layout_height="wrap_content"
android:orientation="vertical"></LinearLayout>
这里是错误信息
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.abhishakkrmalviya.perfecthalf/com.abhishakkrmalviya.perfecthalf.GetNames}: android.content.res.Resources$NotFoundException: String resource ID #0x0
【问题讨论】:
-
我的例子对你有帮助吗?