[英]How do I display a UUID in a TextView?
I would like to display a unique code
like a uuid
generated using mysql
in a TextView
.我想显示一个unique code
比如在TextView
使用mysql
生成的uuid
。
After creating my database
table and using a trigger to create uuid
, I was able to successfully generate a json
object and implement in android studio using retrofit
.在创建我的database
表并使用触发器创建uuid
,我能够成功生成一个json
对象并android studio using retrofit
在android studio using retrofit
。 However, I am able to display all json
data from mysql
in TextView
but not the uuid
code.但是,我可以在TextView
显示来自mysql
所有json
数据,但不能显示uuid
代码。 The TextView
shows blank. TextView
显示空白。
activity_main.xml活动_main.xml
<androidx.cardview.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/spacing_medium"
android:layout_marginTop="@dimen/spacing_medium"
android:visibility="visible"
app:cardCornerRadius="0dp"
app:cardElevation="2dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@android:color/white"
android:gravity="center_vertical"
android:minHeight="?attr/actionBarSize"
android:orientation="horizontal">
<View
android:layout_width="@dimen/spacing_smlarge"
android:layout_height="wrap_content" />
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Unique Code"
android:textAppearance="@style/TextAppearance.AppCompat.Subhead"
android:textColor="@color/grey_80" />
<TextView
android:id="@+id/unique_code"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="@dimen/spacing_large"
android:text="CXDT2887A"
android:textAppearance="@style/Base.TextAppearance.AppCompat.Title"
android:textColor="@color/colorAccent" />
<ImageButton
android:id="@+id/bt_copy_code"
android:layout_width="?attr/actionBarSize"
android:layout_height="?attr/actionBarSize"
android:background="?attr/selectableItemBackgroundBorderless"
android:tint="@color/grey_60"
app:srcCompat="@drawable/ic_content_copy" />
</LinearLayout>
</LinearLayout>
</androidx.cardview.widget.CardView>
User.java用户.java
public class User {
private int id;
private String uuid;
private String email;
private String firstname;
private String lastname;
private String companyname;
private String postcode;
private String city;
private String state;
private String phonenumber;
private String address;
private String country;
private String status;
private int currency;
private String language;
private int email_verified;
private String photo;
public User(int id, String uuid, String email, String firstname, String lastname, String companyname, String address, String city,
String state, String postcode, String country, String phonenumber, String status, int currency,
String language, int email_verified, String photo) {
this.id = id;
this.uuid = uuid;
this.email = email;
this.firstname = firstname;
this.lastname = lastname;
this.companyname = companyname;
this.address = address;
this.city = city;
this.state = state;
this.postcode = postcode;
this.country = country;
this.phonenumber = phonenumber;
this.status = status;
this.currency = currency;
this.language = language;
this.email_verified = email_verified;
this.photo = photo;
}
public int getId() {
return id;
}
public String getUuid() {
return uuid;
}
public String getEmail() {
return email;
}
public String getFirstName() {
return firstname;
}
public String getLastName() {
return lastname;
}
public String getCompanyName() { return companyname; }
public String getAddress() {
return address;
}
public String getCity() {
return city;
}
public String getState() { return state; }
public String getPostcode() {
return postcode;
}
public String getCountry() {
return country;
}
public String getPhonenumber() {
return phonenumber;
}
public String getStatus() { return status; }
public int getCurrency() { return currency; }
public String getLanguage() {
return language;
}
public int getEmail_verified() { return email_verified; }
public String getPhoto() {
return photo;
}
}
MainActivity.java主活动.java
tv_unique_code = (TextView) findViewById(R.id.unique_code);
bt_copy_code = (ImageButton) findViewById(R.id.bt_copy_code);
bt_copy_code.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Tools.copyToClipboard(getApplicationContext(), tv_unique_code.getText().toString());
}
});
tv_unique_code.setText(SharedPrefManager.getInstance(MainActivity.this).getUser().getUuid());
parent_view = findViewById(android.R.id.content);
if you are loading the object with a string from:如果您使用以下字符串加载对象:
String myId = UUID.randomUUID().toString();
You can set the textview to the id by:您可以通过以下方式将 textview 设置为 id:
Textview displayId= (TextView) findViewById(R.id.display_id);
displayId.setText(User.getId());
Hope that answered your question, if not please provide more code of the activity :)希望回答了您的问题,如果没有请提供更多活动代码:)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.