【发布时间】:2020-09-11 16:06:52
【问题描述】:
我正在尝试处理一些 Android Java 内容,但在处理 Toast 消息时遇到了一些麻烦。我的范围能够从另一个 ArrayList 调用的字符串数组中发布随机 toast 消息。我想出了如何将它们分别打印出来,尽管我觉得在 toast 语法方面我可能会遗漏很多东西。
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ListView myListView = findViewById(R.id.myListView);
final ArrayList<String> myFamily = new ArrayList<>(asList("Giovani", "Enu", "Xochle", "Rquel", "Falsto", "Bam", "Duncan", "Goose", "Edgar", "Frank"));
ArrayList<String> gio = new ArrayList<>(asList(" His other brother ", " Met in high school ", " Played on the same sports team ", " Has two kids "));
ArrayList<String> karina = new ArrayList<>(asList(" His youngest sister ", " Kinda short ", " Sweet but kinda dumb "));
ArrayList<String> midget = new ArrayList<>(asList(" His Second youngest sister ", " Kinda short ", " Kinda a crazy cat lady ", " Cannot handle her liquor "));
ArrayList<String> ma = new ArrayList<>(asList(" His other mother ", " Works way too hard ", " Sweetest lady in the world "));
ArrayList<String> pa = new ArrayList<>(asList(" His other father ", " Not feeling well ", " Good heart hopefully he can live in peace "));
ArrayList<String> me = new ArrayList<>(asList(" The coolest ", " Kinda short ", " Sweet but kinda dumb "));
ArrayList<String> dunks = new ArrayList<>(asList(" Brother from another mother ", " Warrior born ", " Allergic to most things that could hinder combat "));
ArrayList<String> gus = new ArrayList<>(asList(" His other brother ", " Loves cars ", " Talks alot of shit ", " Loves white girls ", " Memorised the metal gear series by heart"));
ArrayList<String> edd = new ArrayList<>(asList(" Oldest of the other brother ", " Mostly quiet outside of social situations ", " Cares about saving his money ", " Laughs alot"));
ArrayList<String> frank = new ArrayList<>(asList(" Other brother ", " Impulsively stupid but loyal ", " Really into recreational passions "));
//ArrayList[] fList = new ArrayList[]{{myFamily.get(0),Bio.get()}, };
final Random chance = new Random();
final ArrayList<ArrayList> bio = new ArrayList (Arrays.asList(gio, karina, midget, ma, pa, me, dunks, gus, edd, frank));
//final int selectChance = chance.nextInt(bio.length);
/*
for (String selection : myFamily)
bio
return ;
}
*/
ArrayAdapter<String> arrayManager = new ArrayAdapter<>(this, android.R.layout.simple_list_item_1, myFamily);
myListView.setAdapter(arrayManager);
myListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
Toast.makeText(getApplicationContext(), "Sup " + bio, Toast.LENGTH_LONG).show();
}
});
}
}
【问题讨论】:
-
所以您有一个列表视图,其中包含
Giovani或Enu之类的名称,当您单击该项目时,您想从列表中随机发送消息,其中包含该名称的句子,例如对于Giovani你想打印来自gio的随机字符串吗?我说的对吗? -
@iknow 是的,这就是我的目标
-
所以看看我的回答,我认为它可以满足您的需求。如果不告诉我,否则您可以投票并接受:D
标签: java android string arraylist random