Answer the question
In order to leave comments, you need to log in
How to make in Android Studio so that the user can add his elements to the array at the click of a button?
I have an array
import kotlin.random.Random.Default.nextInt
fun main() {
val a1 = "Медведь"
val a2 = "Волк"
val a3 = "Лиса"
val a4 = "Заяц"
val a5 = "Лев"
val massive = arrayOf(a1, a2, a3,a4,a5)
val arraySize = massive.size
val randomaiz = nextInt(arraySize)
val animals = "${massive[randomaiz]}"
print(animals)
}
Answer the question
In order to leave comments, you need to log in
I can’t help with Kotlin, because I don’t know, but in Java this is done by intent.putExtra()
Pass it like this (in one Activity):
public void editcontent(int position){
Intent intent = new Intent(mContext, EditUserItemAd.class);
intent.putExtra("adid", adid.get(position));
intent.putExtra("image1_url", mImages1.get(position));
intent.putExtra("image2_url", mImages2.get(position));
intent.putExtra("image3_url", mImages3.get(position));
intent.putExtra("short_name", shortNames.get(position));
intent.putExtra("full_name", fullNames.get(position));
intent.putExtra("ad_price", price.get(position));
intent.putExtra("ad_currency", currency.get(position));
intent.putExtra("ad_neworused", neworused.get(position));
intent.putExtra("ad_category1", adcat_ind1.get(position));
intent.putExtra("ad_category2", adcat_ind2.get(position));
intent.putExtra("imagename1", Imagename1.get(position));
intent.putExtra("imagename2", Imagename2.get(position));
intent.putExtra("imagename3", Imagename3.get(position));
intent.putExtra("adactivated", activated.get(position));
mContext.startActivity(intent);
}
private void getIncomingIntent() throws JSONException {
Log.d(TAG, "getIncomingIntent: checking for incoming intents.");
if(getIntent().hasExtra("image1_url") && getIntent().hasExtra("short_name")){
Log.d(TAG, "getIncomingIntent: found intent extras.");
String useradid = getIntent().getStringExtra("adid");
String image1Url = getIntent().getStringExtra("image1_url");
String image2Url = getIntent().getStringExtra("image2_url");
String image3Url = getIntent().getStringExtra("image3_url");
String shortName = getIntent().getStringExtra("short_name");
String fullName = getIntent().getStringExtra("full_name");
String price = getIntent().getStringExtra("ad_price");
String currency = getIntent().getStringExtra("ad_currency");
String condition = getIntent().getStringExtra("ad_neworused");
String category1 = getIntent().getStringExtra("ad_category1");
String category2 = getIntent().getStringExtra("ad_category2");
String imagename1 = getIntent().getStringExtra("imagename1");
String imagename2 = getIntent().getStringExtra("imagename2");
String imagename3 = getIntent().getStringExtra("imagename3");
String adactive = getIntent().getStringExtra("adactivated");
photopath0 = imagename1;
photopath1 = imagename2;
photopath2 = imagename3;
makeItemInterface(useradid, image1Url, image2Url, image3Url, shortName, fullName, price,currency,condition, category1,category2, adactive);
}
}
This thing is called a data model.
It must be able to save data between application launches.
At the first start of the application - initialization with initial data.
In the future, restoring the current state.
In the add activity, you simply call the model
's insert_new_value() method. In the greetings activity, the give_random_name() method
For storage, you can use room, sharedPreferns, work with files on your own.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question