我的android编码有问题。我要进行更新。但首先,我正在尝试从编辑文本,微调器和图像中收集所有数据。但是我对微调器和图像有问题,无法获取以前的数据。如何使用微调器和图像获取以前的数据?例如:图片1
当用户单击“提交”按钮时,
显示完整的检索过程,然后它将转到该“查看活动”界面。在Image2中
显示“编辑活动”界面,当用户单击“编辑”按钮时,用户可以在此处更新所有数据。现在的问题是,我无法使用微调器和图像来收集先前的数据,以进行编辑/更新,如图2所示。我真的希望有人可以帮助我。。在此先感谢...
编码如下:
1)通过“查看活动”进行编码:-
EditAdsButton.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View v)
{
Intent editAds = new Intent(ViewAdsActivity.this, EditAdsActivity.class);
startActivity(editAds);
String tn = ViewTuitionName.getText().toString();
String pn = ViewProviderName.getText().toString();
String pg = getIntent().getStringExtra("PG");
Intent i = new Intent(ViewAdsActivity.this, EditAdsActivity.class);
i.putExtra("TN", "" +tn); // Collected from EditText or any other source
i.putExtra("PN", "" +pn);
i.putExtra("PG", "" +pg);
startActivity(i);
}
});
2)通过“编辑活动”(onCreate方法)进行编码:-
Intent i = getIntent();
String tn = i.getStringExtra("TN");
String pn = i.getStringExtra("PN");
String pg = getIntent().getStringExtra("PG");
EditTuitionName.setText(tn);
EditProviderName.setText(pn);
EditProviderGender.setSelection(pg);
答案 0 :(得分:0)
对于微调框,您可以使用
Spinner mySpinner = (Spinner) findViewById(R.id.your_spinner);
String text = mySpinner.getSelectedItem().toString();
然后将文本与其他对象一样放置在意图中。
图像比较棘手,因为您不想序列化意图的位图,因为序列化位于主线程上,应用程序可能会停顿或挂起一点。相反,您可以将位图存储在两个活动都可以访问的类中,或者,如果图像已存储在设备上,则可以传递URI并在下一个活动中重新打开它。
答案 1 :(得分:0)
这是一个解决方案:
Constant.java
public class Constant {
public static final String[] GENDER = {"Male", "Female", "Other"};
}
ViewAdsActivity.java
public class ViewAdsActivity extends AppCompatActivity {
private CircleImageView avatar;
private EditText name;
private Spinner gender;
private Button next;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_view_ads);
avatar = findViewById(R.id.avatar);
name = findViewById(R.id.edit_text_name);
gender = findViewById(R.id.spinner_gender);
next = findViewById(R.id.button_next);
// Render avatar
String imageUrl = "https://vignette.wikia.nocookie.net/spiritedaway/images/6/69/Chihiro.jpg/revision/latest?cb=20170308090934";
avatar.setTag(imageUrl);
Picasso.get()
.load(imageUrl)
.into(avatar);
// Render spinner
ArrayAdapter<String> adapter = new ArrayAdapter<>(this, android.R.layout.simple_list_item_1, Constant.GENDER);
gender.setAdapter(adapter);
next.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(ViewAdsActivity.this, EditAdsActivity.class);
intent.putExtra("imageUrl", (String) avatar.getTag());
intent.putExtra("genderPosition", gender.getSelectedItemPosition());
intent.putExtra("name", name.getText().toString());
startActivity(intent);
}
});
}
}
EditAdsActivity.java
public class EditAdsActivity extends AppCompatActivity {
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_view_ads);
CircleImageView avatar = findViewById(R.id.avatar);
EditText nameEditText = findViewById(R.id.edit_text_name);
Spinner gender = findViewById(R.id.spinner_gender);
String imageUrl = getIntent().getStringExtra("imageUrl");
int genderPosition = getIntent().getIntExtra("genderPosition", 0);
String name = getIntent().getStringExtra("name");
// Render image view
Picasso.get()
.load(imageUrl)
.into(avatar);
// Render spinner
ArrayAdapter<String> adapter = new ArrayAdapter<>(this, android.R.layout.simple_list_item_1, Constant.GENDER);
gender.setAdapter(adapter);
gender.setSelection(genderPosition);
// Render edit text
nameEditText.setText(name);
}
}