简体   繁体   English

EditText的Android setText

[英]Android setText of an EditText

I'm trying to pass in a book title from a SearchScreen to an InventoryAddScreen when the book is not found in the inventory. 我想在清单中找不到图书时,将图书标题从SearchScreen传递到InventoryAddScreen。 InventoryAddScreen has a couple EditText to allow users to input various book information such as Author and ISBN. InventoryAddScreen有一对EditText,允许用户输入各种书籍信息,如作者和ISBN。 I want to predefine the book title EditText field based on what's being passed in from the Search Screen. 我想根据从搜索屏幕传入的内容预定义书名EditText字段。 However, I still want to be able to edit that EditText if I accidentally misspelled the book title. 但是,如果我不小心拼错了书名,我仍然希望能够编辑EditText。

InventoryAddScreen.java InventoryAddScreen.java

Intent intent = getIntent();
final String userName = intent.getExtras().getString("username");
final String title = intent.getExtras().getString("title");

inputTitle=(EditText)findViewById(R.id.inputTitle);
inputTitle.setText(title);

inventory.xml inventory.xml

<EditText
    android:id="@+id/inputTitle"
    android:hint="Input Title"
    android:inputType="text"
    android:textColorHint="@color/hintGray"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    >

    <requestFocus />
</EditText>

However, whenever I run the program, the EditText only shows the hint and not my setText value. 但是,每当我运行程序时,EditText只显示提示而不是我的setText值。 (I'm fairly certain that the title extra is being passed in because I can use the userName extra.) (我很确定额外的标题是传入的,因为我可以使用额外的userName。)

How do I pre-set the inputTitle EditText as the title passed in from the getIntent? 如何将inputTitle EditText预先设置为从getIntent传入的标题?

Hi please check the logs that you are getting correct value from intent or not? 嗨,请检查您是否从意图获得正确值的日志? may be data is not passed correctly. 可能是数据未正确传递。 so please investigate , beside this you can check the passed data value and received values with logs and check the key name of the passed data as well. 所以请调查,除此之外,您可以检查传递的数据值和接收的日志值,并检查传递的数据的密钥名称。 In Short Please check passed values through the intent. 简短请通过意图检查传递的值。

raise the answer if it is feasible 如果可行的话,提出答案

嗨我检查你的代码它正常工作它唯一的一个问题是意图是空或空白所以请检查它。

可能你正在寻找inputTitle.setHint("DATA FROM INTENT");

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM