I'm trying to pass in a book title from a SearchScreen to an InventoryAddScreen when the book is not found in the inventory. InventoryAddScreen has a couple EditText to allow users to input various book information such as Author and ISBN. I want to predefine the book title EditText field based on what's being passed in from the Search Screen. However, I still want to be able to edit that EditText if I accidentally misspelled the book title.

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

<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. (I'm fairly certain that the title extra is being passed in because I can use the userName extra.)

How do I pre-set the inputTitle EditText as the title passed in from the 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

其他提示

Hi i check your code it work properly its only one problem is intent is null or blank so please check it.

may be you are looking for inputTitle.setHint("DATA FROM INTENT");

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top